Removing callable() from the stdlib
I've been running 2to3's fix_callable over 2.6's stdlib to remove -3 warnings due to callable() usage; 2to3 replaces callable(x) with has_attr(x, "__call__"). Unfortunately, this breaks code that wants to run callable() on old-style classes (like test_builtin), because old-style classes don't have a __call__ attribute (new-style classes do, however). How should this be handled? I'm tempted to just add __call__ to old-style classes for 2.6, but Neal Norwitz thought that might break some user code. Any other thoughts? Collin Winter
On Fri, Mar 28, 2008 at 10:51 AM, Collin Winter <collinw@gmail.com> wrote:
I've been running 2to3's fix_callable over 2.6's stdlib to remove -3 warnings due to callable() usage; 2to3 replaces callable(x) with has_attr(x, "__call__"). Unfortunately, this breaks code that wants to run callable() on old-style classes (like test_builtin), because old-style classes don't have a __call__ attribute (new-style classes do, however).
How should this be handled? I'm tempted to just add __call__ to old-style classes for 2.6, but Neal Norwitz thought that might break some user code. Any other thoughts?
I don't see how this would break user code, as long as the __call__ shows up for the *class* but not for the *instance*, and as long as it doesn't break users overriding __call__ in a classic class to make the instances callable. -- --Guido van Rossum (home page: http://www.python.org/~guido/)
On Fri, Mar 28, 2008 at 12:58 PM, Guido van Rossum <guido@python.org> wrote:
On Fri, Mar 28, 2008 at 10:51 AM, Collin Winter <collinw@gmail.com> wrote:
I've been running 2to3's fix_callable over 2.6's stdlib to remove -3 warnings due to callable() usage; 2to3 replaces callable(x) with has_attr(x, "__call__"). Unfortunately, this breaks code that wants to run callable() on old-style classes (like test_builtin), because old-style classes don't have a __call__ attribute (new-style classes do, however).
How should this be handled? I'm tempted to just add __call__ to old-style classes for 2.6, but Neal Norwitz thought that might break some user code. Any other thoughts?
I don't see how this would break user code, as long as the __call__ shows up for the *class* but not for the *instance*, and as long as it doesn't break users overriding __call__ in a classic class to make the instances callable.
Yep, I was only going to make it appear on the class. I'll go ahead and whip up a patch. Collin
participants (2)
-
Collin Winter
-
Guido van Rossum