On 25 août 20:52, Duncan Findlay wrote: > A constant value -1 results in different astng trees between the > compiler.ast implementation for Python 2.4 and the _ast > implementation for 2.5 and 2.6 > > With Python 2.4 (compiler.ast), we get: > > UnaryOp(op='-', operand=Const(1)) > > With Python 2.5, 2.6 (_ast) we get: > > Const(-1) > > > Which is right? Also, is there an easy way to dump an astng tree? (I > typed all of the above manually, and found this out by playing > around in the interpreter...)
from logilab.astng.nodes import native_repr_tree, _repr_tree the former should be used on bare ast (eg returned by compiler.parse w/ py < 2.5 and compile(string, "<string>", 'exec', PyCF_ONLY_AST) w/ py >= 2.5. The later is designed to be used on astng 'unified' trees. > Are differences between the two > implementations common or are these bugs and should they be reported > as such? (The README._ast_compatibility file says "The work is not > yet finished: XXX insert what's missing here." :-) ) well, the work is now considered as finished, since've produced a good enough unification, at least for pylint. This README however is mostly deprecated. But it may be that some differences such as the one you noticed are still there, but imo this is not a problem as long as it doesn't trigger some error / false positive / false negative in pylint. If you want to use astng for another purpose and would like this to be unified, I can help you to acheive this of course. And at last, we usually prefer the py >=2.5 ast structure, because it often makes more sense and is oriented towards the future, of course (provided a pragmatic migration path may be found). -- Sylvain Thénault LOGILAB, Paris (France) Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations Développement logiciel sur mesure: http://www.logilab.fr/services CubicWeb, the semantic web framework: http://www.cubicweb.org _______________________________________________ Python-Projects mailing list [email protected] http://lists.logilab.org/mailman/listinfo/python-projects
