mirror of
https://github.com/davidhalter/parso.git
synced 2026-02-03 16:43:01 +08:00
Iter raise statements in a Function (#16)
* Add Function.iter_raise_stmts method and tests * Add Alisdair Robertson to AUTHORS.txt * Cleanup Function.iter_raise_stmts and test Decided not to try and exclude exceptions that would be caught by a try-catch
This commit is contained in:
committed by
Dave Halter
parent
50445f424e
commit
647073b1b9
@@ -592,6 +592,21 @@ class Function(ClassOrFunc):
|
||||
|
||||
return scan(self.children)
|
||||
|
||||
def iter_raise_stmts(self):
|
||||
"""
|
||||
Returns a generator of `raise_stmt`. Includes raise statements inside try-except blocks
|
||||
"""
|
||||
def scan(children):
|
||||
for element in children:
|
||||
if element.type == 'raise_stmt' \
|
||||
or element.type == 'keyword' and element.value == 'raise':
|
||||
yield element
|
||||
if element.type in _RETURN_STMT_CONTAINERS:
|
||||
for e in scan(element.children):
|
||||
yield e
|
||||
|
||||
return scan(self.children)
|
||||
|
||||
def is_generator(self):
|
||||
"""
|
||||
:return bool: Checks if a function is a generator or not.
|
||||
|
||||
Reference in New Issue
Block a user