def iter_node(self, node):
silence = (ast.Expr,)
if not isinstance(node, silence):
try:
body = node.body
# check if is iterable
list(body)
except TypeError:
body = [node.body]
except AttributeError:
body = None
yield node, body
for attr in ('value', 'func', 'right', 'left'):
if hasattr(node, attr):
value = getattr(node, attr)
# reversed is used here so matches are returned in the
# sequence they are read, eg.: foo.bar.bang
for n in reversed(list(self.iter_node(value))):
yield n
评论列表
文章目录