Message241360
I have closed the issue because the code behaves according to the language specs and the language design. It is not broken at all. The callable test just checks for the attribute __call__ on the *type* of an object. The check is not performed on the *object* itself.
In your example
callable(a)
does not do
hasattr(a, '__call__')
but
hasattr(type(a), '__call__')
which translates to
hasattr(A, '__call__')
The behavior is very well consistent. I presume it just doesn't match your expectations. Special methods have a slightly different lookup behavior than ordinary. Due to the highly dynamic nature of Python the __call__ attribute is not validated at all.
For example this is expected behavior:
>>> class Example:
... __call__ = None
...
>>> callable(Example())
True
>>> class Example:
... __call__ = None
...
>>> example = Example()
>>> callable(example)
True
>>> example()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable |
|
Date |
User |
Action |
Args |
2015-04-17 20:14:45 | christian.heimes | set | recipients:
+ christian.heimes, ionelmc, Claudiu.Popa, llllllllll |
2015-04-17 20:14:45 | christian.heimes | set | messageid: <1429301685.22.0.874170676642.issue23990@psf.upfronthosting.co.za> |
2015-04-17 20:14:45 | christian.heimes | link | issue23990 messages |
2015-04-17 20:14:45 | christian.heimes | create | |
|