Comment 6 for bug 244677

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

I think to say that "the rules about when __getattr__ gets called are being obeyed" is a bit of an overstatement considering that 'myfunc()' [with parens] is not a *legal* attribute name: (http://docs.python.org/ref/attribute-references.html -- http://docs.python.org/ref/identifiers.html).

It appears that %autocall has a couple of nasty side-effects regarding attribute access. In this case, it's fabricating a false attribute name -- one that was never requested. Another problem is that it allows syntax-errors to propagate way further than standard-Python would allow:

For example, in IPython:

  In [15]: f.'blah()' ## Notice the quotes around the attribute -- this is a syntax error
  Getting "'blah()'" ## Still calls __gettattr__
  ------------------------------------------------------------
     File "<ipython console>", line 1
       f.'blah()'
              ^
  SyntaxError: invalid syntax ## Finally produces a syntax-error

Standard-Python recognizes the syntax-error and never passes it to __getattr__:
  >>> f.'blah()'
    File "<stdin>", line 1
      f.'blah()'
             ^
  SyntaxError: invalid syntax