Comment 0 for bug 244677

Revision history for this message
Angelo Bonet (abonet) wrote : IPython calls an object's __getattr__ inconsistently

Python 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.