[issue15987] Provide a way to compare AST nodes for equality recursively

2012-09-20 Thread Julian Berman
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

[issue15987] Provide a way to compare AST nodes for equality recursively

2012-09-20 Thread STINNER Victor
Changes by STINNER Victor : -- nosy: +haypo ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.

[issue15987] Provide a way to compare AST nodes for equality recursively

2012-09-21 Thread Brett Cannon
Changes by Brett Cannon : -- nosy: +brett.cannon ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.py

[issue15987] Provide a way to compare AST nodes for equality recursively

2012-09-21 Thread Benjamin Peterson
Benjamin Peterson added the comment: This is a reasonable request. Should comparison include lineno/col_offset or not? If you implement, __eq__, you should also implement __hash__. Maybe, it would be best to start with a helper comparison function in the ast module. -- nosy: +benjamin.

[issue15987] Provide a way to compare AST nodes for equality recursively

2012-09-21 Thread Julian Berman
Julian Berman added the comment: I'd say yes (to both lineno/col_offset). And yeah that sounds like what I had in mind (a helper function). If I'm specific for a moment about implementation, perhaps something like `ast.diff`, which yielded tuples of differing nodes (in say, breadth first orde

[issue15987] Provide a way to compare AST nodes for equality recursively

2012-09-21 Thread Terry J. Reedy
Changes by Terry J. Reedy : -- stage: -> test needed versions: -Python 3.3 ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue15987] Provide a way to compare AST nodes for equality recursively

2012-09-22 Thread Benjamin Peterson
Benjamin Peterson added the comment: Yes, though some things like what to return if one has an entire subtree that the other doesn't have will have to be worked out. -- ___ Python tracker _

[issue15987] Provide a way to compare AST nodes for equality recursively

2013-03-26 Thread Brett Cannon
Brett Cannon added the comment: I have a use for this as well, but w/o the lineno/col_offset comparison and all I need is a True/False result. -- ___ Python tracker ___

[issue15987] Provide a way to compare AST nodes for equality recursively

2013-03-26 Thread Brett Cannon
Brett Cannon added the comment: IOW I think a function that uses ast.walk() and has flags for specifying whether _attributes should also be checked and then uses a class check and then uses _fields to do all other checking. -- ___ Python tracker