This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年09月09日 00:15 by Albert.Zeyer, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (3) | |||
|---|---|---|---|
| msg170070 - (view) | Author: Albert Zeyer (Albert.Zeyer) * | Date: 2012年09月09日 00:14 | |
Code:
```
class Wrapper:
@staticmethod
def __getattr__(item):
return repr(item) # dummy
a = Wrapper()
print(a.foo)
```
Expected output: 'foo'
Actual output with Python 2.7:
Traceback (most recent call last):
File "test_staticmethodattr.py", line 7, in <module>
print(a.foo)
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): @staticmethod def __getattr__(item): return repr(item) # dummy a = Wrapper() print(a.foo) # '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?
|
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:35 | admin | set | github: 60089 |
| 2012年09月09日 10:09:54 | Albert.Zeyer | set | messages: + msg170093 |
| 2012年09月09日 03:04:17 | eric.snow | set | status: open -> closed nosy: + eric.snow messages: + msg170076 resolution: rejected |
| 2012年09月09日 00:15:08 | Albert.Zeyer | create | |