On 06 octobre 10:57, Marc-Antoine Ruel wrote: > Le 6 octobre 2010 04:37, Sylvain Thénault <[email protected]> a > écrit : > > I'm afraid all this would require some changes in astng to store such > > inference > > tips. Currently, type inference works by navigating into the ast, also > > there > > is no notion of "variable x". In the code > > > > 1. assert isinstance(x, A) > > 2. x.method() > > > > astng sees both statements as unrelated (it only knows nodes of the ast). > > One > > can use node.infer() (where node is a Name node for instance) to try to > > resolve > > its possible values. This works basically by filtering assigments and > > resolving > > them until we reach a "final" node like a typed constant, a class instance, > > etc. > > > > That's where I was thinking about to hook up; basically having a function > similar to astng.interence.infer_ass() for nodes.Assert.infer() that would > match for the very specific subset of self.test==CallFunc(instance, Name, > Name).
IMO that detection has to be done during astng building step, as we already do for monkey patch detection (grep for delayed_attr in astng/rebuilder.py). > > So to make this work we should first store type annotation (extracted from > > detected calls to isinstance as proposed, python 3 annotations... during > > astng > > building step), then detect and use them when infering. > > > > You should first take a look at LocalsDictNodeNG / scope lookup. > > > > >From what I understand, a change would be required in > node_classes.LookupMixIn._filterstmts(). Righ I think, to use annotations collected during the building step. > If you dig you'll see that indeed astng has a somewhat "flat" representation > > and is not well able to handle data flow... > > I assume that would be a huge amount work to improve this. :/ indeed, that won't change tomorrow -- 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
