[issue13258] replace hasattr(obj, '__call__') with callable(obj)
Florent Xicluna
report at bugs.python.org
Tue Oct 25 00:18:39 CEST 2011
Florent Xicluna <florent.xicluna at gmail.com> added the comment:
We have so many alternatives, it's funny ...
def callable(obj):
return hasattr(obj, '__call__') or hasattr(obj, '__bases__')
def callable(obj):
return isinstance(obj, collections.abc.Callable)
def callable(obj):
return hasattr(obj, '__call__') or type(obj) == types.ClassType
def callable(obj):
return any("__call__" in klass.__dict__
for klass in type(obj).__mro__)
----------
stage: -> patch review
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13258>
_______________________________________
More information about the Python-bugs-list
mailing list