[issue13258] replace hasattr(obj, '__call__') with callable(obj)

STINNER Victor report at bugs.python.org
Mon Oct 24 23:44:58 CEST 2011


STINNER Victor <victor.stinner at haypocalc.com> added the comment:

callable() is not just faster, it's also "more correct": hasattr(obj, "__call__") doesn't call base classes. See callable() of the six module:


def callable(obj):
  return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)

----------
nosy: +haypo

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13258>
_______________________________________


More information about the Python-bugs-list mailing list