Title: @staticmethod __getattr__ doesn't work
Type: Stage:
Components: Interpreter Core Versions: Python 2.7
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Albert.Zeyer, eric.snow
Priority: normal Keywords:

Created on 2012-09-09 00:15 by Albert.Zeyer, last changed 2012-09-09 10:09 by Albert.Zeyer. This issue is now closed.

Messages (3)
msg170070 - (view) Author: Albert Zeyer (Albert.Zeyer) Date: 2012-09-09 00:14

class Wrapper:
        def __getattr__(item):
                return repr(item) # dummy

a = Wrapper()

Expected output: 'foo'

Actual output with Python 2.7:

Traceback (most recent call last):
  File "", line 7, in <module>
TypeError: 'staticmethod' object is not callable

Python 3.2 does return the expected ('foo').
PyPy returns the expected 'foo'.
msg170076 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2012-09-09 03:04
In Python 2 the code example generates an old-style class.  When I tried it with a new style class, it worked fine:

class Wrapper(object):
        def __getattr__(item):
                return repr(item) # dummy

a = Wrapper()
# 'foo'

Chalk this up to another reason to move to Python 3.  <wink>
msg170093 - (view) Author: Albert Zeyer (Albert.Zeyer) Date: 2012-09-09 10:09
I don't quite understand. Shouldn't __getattr__ also work in old-style classes?

And the error itself ('staticmethod' object is not callable), shouldn't that be impossible?
Date User Action Args
2012-09-09 10:09:54Albert.Zeyersetmessages: + msg170093
2012-09-09 03:04:17eric.snowsetstatus: open -> closed

nosy: + eric.snow
messages: + msg170076

resolution: rejected
2012-09-09 00:15:08Albert.Zeyercreate