On Saturday 09 October 2010 22:10:07 Daniel Harding wrote: > Emile Anclin wrote: > > On Friday 01 October 2010 20:15:32 Daniel Harding wrote: > >> Currently if pylint is run under Python 2.7 to check a file > >> containing dictionary comprehensions or set comprehensions, it > >> results in an exception in the astng code. > >> > >> The attached patches (against the current hg tip) add support for > >> these constructs to astng. > > > > fabulous, this is half the job of making astng py3k compatible! > > (or at least an important part) > > > > I will apply the patch right now > > Thanks for taking my changes so quickly! However, I realized today > that they weren't completely correct. Dict comprehensions and set > comprehensions should create their own scope, just like generator > expressions. I didn't account for this in my changes, so I have > attached a patch against astng that makes DictComp and SetComp subclass > from LocalsDictNodeNG rather than NodeNG. I also moved their > definitions from node_classes.py to scoped_nodes.py. > ok, thanks for the patches again. applied.
> Once that change was made, I had to make a change to VariableChecker in > pylint to prevent spurious E0602 undefined variable errors. I added > visit_*/leave_* methods for dict and set comprehensions which mirror > the visit_genexpr/leave_genexpr methods. I also changed the scope type > used in visit_genexpr to be 'comprehension' and then reused that for > dict and set comprehensions. Attached is a second patch with these > changes against pylint. applied. (this time for real, your last patch wasn't actually pushed yet ...) > As I was making these changes, I realized that as part of implementing > Python 3 support, both astng and PyLint will need to be able to account > for the fact that under Python 2, list comprehensions use the enclosing > scope, while under Python 3, they create their own scope. I don't know > what the mechanism/architecture will be for making that kind of runtime > decision, so I didn't try to tackle that issue. I filled a ticket about that, just in case we didn't come across it in the tests (I think we will however ...) http://www.logilab.org/ticket/48507 I am working on the astng 3k - port. If you are interested, I think enough is done to make it possible for you (and any body else) to try to solve such kind of issue. Concerning our particular case, after I quick look, I suppose that modification of the scope will have to do somewhere around the LookupMixIn._filter_stmts method. > Also, I hope to implement some tests pylint this week for dict and set > comprehensions - I'll post a patch once I have it. Yes, and probably we should also add tests for DictComp : as you implemented it like ListComp, we might have false negative on def hello(args): things = {a for a in args]} print a # undefined variable 'a' -- Emile Anclin <[email protected]> http://www.logilab.fr/ http://www.logilab.org/ Informatique scientifique & et gestion de connaissances _______________________________________________ Python-Projects mailing list [email protected] http://lists.logilab.org/mailman/listinfo/python-projects
