IPython calls an object's __getattr__ incorrectly
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
IPython |
Incomplete
|
Undecided
|
Unassigned |
Bug Description
IPython seems to call an object's __getattr__ function inconsistently and at times when regular Python does not. According to the Python documentation on __getattr__: "if the attribute is found through the normal mechanism, __getattr__() is not called."
In the following examples, myobj has a bound method named "myfunc" defined and as well as a "__getattr__" method defined.
1) "myobj.myfunc()"
In this example, IPython first calls myobj.__getattr__, before calling myfunc.
2) "myobj.myfunc ()"
Introducing white-space between "myfunc" and "()" eliminates IPython's __getattr__ call
3) "myobj.myfunc( )"
Introducing white-space between the parens "( )" eliminates IPython's __getattr__ call
4) "x = myobj.myfunc()"
In this assignment statement, IPython does not call __getattr__.
In all of the above examples, regular Python *never* calls the object's __getattr__ routine, only myfunc is called.
What version of IPython are you using? With 0.8.3 and the trunk, I do not see this behavior. Can you show us the code that displays the behavior you see?
In [1]: !cat foo.py
IPython system call: cat foo.py
class foo(object):
def __getattr__(self, attr):
print 'Getting %r' % attr
def myfunc(self):
print 'myfunc()'
In [2]: import foo
In [3]: f = foo.foo()
In [4]: f.myfunc()
myfunc()
In [5]: f.myfunc ()
myfunc()
In [6]: f.myfunc( )
myfunc()
In [7]: x = f.myfunc()
myfunc()
In [8]: f.something
Getting 'something'