[Resurrecting this very old thread...]
Did anything ever come of these proposals? It would be extremely helpful
for me to have some way of providing extra type information to pylint,
whether via:
x = f()
assert isinstance(x, MyType)
or via a type annotation:
def f(): # pylint: return-type=MyType
...
or even via some global property in pylintrc, stating that any variable
named 'x' is always of type MyType.
James.
On Wed, Oct 6, 2010 at 11:58 PM, Sylvain Thénault <
[email protected]> wrote:
> 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
>
_______________________________________________
Python-Projects mailing list
[email protected]
http://lists.logilab.org/mailman/listinfo/python-projects