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:
Alisdair Robertson
2017-10-28 22:35:49 +11:00
committed by Dave Halter
parent 50445f424e
commit 647073b1b9
3 changed files with 47 additions and 0 deletions

View File

@@ -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.