[issue23990] Callable builtin doesn't respect descriptors

Alexander Belopolsky report at bugs.python.org
Sat Apr 18 01:00:44 CEST 2015


Alexander Belopolsky added the comment:

>From <https://mail.python.org/pipermail/python-ideas/2015-April/033018.html>:


>>>>>>> GvR <<<<<<<<<<
I think you've found an unintended and undocumented backdoor. I admit I don't understand how this works in CPython. Overloaded operators like __add__ or __call__ should be methods in the class, and we don't look for them in the instance. But somehow defining them with @property works (I guess because @property is in the class).

What's different for __call__ is that callable() exists. And this is probably why I exorcised it Python 3.0 -- but apparently it's back. :-(

In the end callable() doesn't always produce a correct answer; but maybe we can make it work in this case by first testing the class and then the instance? Something like (untested):

def callable(x):
    return hasattr(x.__class__, '__call__') and hasattr(x, '__call__')

>>>>>>> GvR <<<<<<<<<<

----------
nosy: +belopolsky
resolution: not a bug -> 
stage: resolved -> 
status: closed -> open

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


More information about the Python-bugs-list mailing list