Message241375
| Author |
belopolsky |
| Recipients |
Claudiu.Popa, belopolsky, christian.heimes, ethan.furman, ionelmc, llllllllll |
| Date |
2015年04月17日.23:00:44 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1429311644.24.0.0757297074625.issue23990@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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 <<<<<<<<<< |
|