[Python-projects] Inferring bound methods with ASTNG
Dave Borowitz
dborowitz at google.com
Thu Aug 16 16:12:53 CEST 2007
Hi Logilab,
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.
Thanks again,
David Borowitz
Google Engineering Intern
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.logilab.org/pipermail/python-projects/attachments/20070816/25fc66fb/attachment.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: instancemethods.diff
Type: text/x-patch
Size: 3148 bytes
Desc: not available
Url : http://lists.logilab.org/pipermail/python-projects/attachments/20070816/25fc66fb/attachment.bin
More information about the Python-Projects
mailing list