[Python-projects] Inferring bound methods with ASTNG
Sylvain Thénault
sylvain.thenault at logilab.fr
Thu Aug 16 17:38:09 CEST 2007
On Thursday 16 August à 16:18, Sylvain Thénault wrote:
> On Thursday 16 August à 10:12, Dave Borowitz wrote:
> > Hi Logilab,
>
> Hey,
>
> > For a pylint checker I'm working on, I want to be able to tell whether the
> > callee of a particular CallFunc is a bound or unbound instance method. The
> > current inference structure doesn't seem to be able to do this. For example, if
> > I have a class Foo with a method bar, then calling infer() on both of the
> > following returns exactly the same Function node:
> > Foo.bar
> > Foo().bar
> >
> > My solution to this issue is to introduce an InstanceMethod proxy that is
> > analogous to the Instance proxy, and wrap any Functions inferred in
> > Instance.igetattr() in InstanceMethod proxies. This means, for the above
> > examples:
> > Foo.bar -> infers a Function
> > Foo().bar -> infers an InstanceMethod (proxying Foo.bar)
> >
> > If there is already a way to do this in logilab-astng, please let me know.
> > Otherwise, if you are interested, I have attached a patch.
>
> there is no way for this yet, so I'm interested in your patch. I'll
> review and check it in asap. Thanks !
just one thing: would you mind to write a test for this in
unittest_inference.py ?
thx
--
Sylvain Thénault LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian: http://www.logilab.fr/formations
Développement logiciel sur mesure: http://www.logilab.fr/services
Python et calcul scientifique: http://www.logilab.fr/science
More information about the Python-Projects
mailing list