The major problem with ast.walk is that it uses an unspecified order for
visiting nodes. The new dump method of the NewShowData class prints
statements in the ast.walk order, which is incomprehensible. ast.walk may
as well be putting the nodes in a blender.
def dump(self, fn, root):
suppress = [
'arg', 'arguments', 'comprehension', 'keyword',
'Attribute', 'BinOp', 'BoolOp', 'Dict', 'IfExp', 'Index',
'Load', 'List', 'ListComp', 'Name', 'NameConstant', 'Num',
'Slice', 'Store', 'Str', 'Subscript', 'Tuple', 'UnaryOp',
]
errors = set()
for node in ast.walk(root):
name = node.__class__.__name__
if name not in suppress:
try:
print('%15s: %s' % (name, self.format(node,strip=False)))
except AttributeError:
errors.add(name)
g.trace('errors', sorted(errors))
I did this experiment to see whether a walk that *did* visit nodes in a
specified order would be useful. Perhaps, but the more I think about this,
the better the typical traverser code looks.
*Summary*
ast.walk is useful only when reporting aggregate data about an ast tree.
Edward
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.