Christian Heimes added the comment:

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

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23990>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to