New submission from Julian Berman:

As is, as far as I can tell, there's no way to easily compare two AST nodes to 
see if they have the same children and same fields (recursively).

I'm writing some unit tests for a NodeTransformers, so I've settled for 
comparing `ast.dump()`s of each, which is kind of dirty, but 1) works and 2) 
produces reasonable failure messages. (As a side note of what else I've tried, 
comparing, say, a list of the `iter_child_nodes` is not a good alternative, 
since the tests I'm writing are making assertions that a given node was not 
modified, which means they deepcopy the node and then want to assert that the 
"transformed" node is unchanged.)

I don't know the global implications of changing ast.AST.__eq__ to know if 
that's feasible (hopefully someone will comment on that), but if it isn't, 
another provided way would be nice.

----------
components: Library (Lib)
messages: 170826
nosy: Julian
priority: normal
severity: normal
status: open
title: Provide a way to compare AST nodes for equality recursively
type: enhancement
versions: Python 3.3, Python 3.4

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue15987>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to