Issue 12501: callable(): remove/amend the deprecation warning in Python 2.7 (original) (raw)
Python 2.7 emits a DeprecationWarning warning if callable() is called and python has the -3 option. callable() was removed in Python 3.0, but it was also added again in Python 3.2 (issue #10518).
$ ./python -bb -3 -Werror Python 2.7.2+ (2.7:7bfedb159e82, Jul 5 2011, 13:23:38)
callable(int) Traceback (most recent call last): File "", line 1, in DeprecationWarning: callable() not supported in 3.x; use isinstance(x, collections.Callable)
I propose to drop the warning from Python 2.7. Use the six module if you would like to support Python 3.1, or use directly the following workaround in your code:
def callable(obj): return any("call" in klass.dict for klass in type(obj).mro)
Attached patch removes the warning.
By the way, the six should be updated for Python 3.2: callable is a builtin again ;-)