[issue7006] The replacement suggested for callable(x) in py3k is not equivalent

Ezio Melotti report at bugs.python.org
Sat Oct 3 08:13:29 CEST 2009

Ezio Melotti <ezio.melotti at gmail.com> added the comment:

Benjamin already replaced hasattr(x, "__call__") with hasattr(type(x),
"__call__") in the Python 3.0 "What's New" in r75090 and r75094, but
this still doesn't match completely the behavior of callable():

>>> class Foo(object): pass
>>> foo = Foo()
>>> callable(foo)
>>> hasattr(type(foo), '__call__')
>>> foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'Foo' object is not callable

There are also other places where hasattr(x, "__call__") is still
suggested/used (e.g. PEP3100).

nosy: +benjamin.peterson

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list