This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: callable(): remove/amend the deprecation warning in Python 2.7
Type: behavior Stage: resolved
Components: Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, eric.araujo, flox, pitrou, python-dev, vstinner
Priority: normal Keywords: patch

Created on 2011-07-05 11:35 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
callable_warning.patch vstinner, 2011-07-05 11:35
Messages (4)
msg139853 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-07-05 11:35
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 "<stdin>", line 1, in <module>
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 ;-)
msg139882 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-07-05 15:45
What about this change instead:

-    if (PyErr_WarnPy3k("callable() not supported in 3.x; "
+    if (PyErr_WarnPy3k("callable() not supported in 3.1; "
msg140007 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-07-08 00:08
New changeset 1f814faaf54d by Victor Stinner in branch '2.7':
Close #12501: Adjust callable() warning: callable() is only not supported in
http://hg.python.org/cpython/rev/1f814faaf54d
msg151923 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-01-24 20:05
New changeset 62bd0553693f by Florent Xicluna in branch '2.7':
Issue #12501: merge the discordant NEWS entries.
http://hg.python.org/cpython/rev/62bd0553693f
History
Date User Action Args
2022-04-11 14:57:19adminsetgithub: 56710
2012-01-24 20:05:55python-devsetmessages: + msg151923
2011-10-24 07:36:38floxsetnosy: + flox
type: behavior
2011-07-08 00:08:04python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg140007

resolution: fixed
stage: resolved
2011-07-05 15:45:58eric.araujosetnosy: + eric.araujo

messages: + msg139882
title: callable(): remove the deprecation warning from Python 2.7 -> callable(): remove/amend the deprecation warning in Python 2.7
2011-07-05 11:35:49vstinnercreate