Message241431
| Author |
christian.heimes |
| Recipients |
Claudiu.Popa, belopolsky, christian.heimes, ethan.furman, ionelmc, jedwards, llllllllll, terry.reedy |
| Date |
2015年04月18日.17:35:09 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1429378510.24.0.470406323809.issue23990@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
All major Python implementation have a mutual agreement that callable() just checks for a __call__ member on the type. You also haven't shown that this behavior violates the documentation and language spec. The check for existence of __call__ on the type is well in the range of expected behavior. I as well as other core devs had the same gut feeling.
Finally your suggestion makes the implementation of callable() more complex and much, much slower. Right now and for more than a decade it is a simple, fast and straight forward code path for new style classes. It just requires two pointer derefs and one comparison to NULL. I'm still -1 on the change.
If you want to go forth with your request then you must write a PEP and convince all implementors of Python implementations to change the current way callable() and other protocols like iter work.
$ python2.7
Python 2.7.8 (default, Nov 10 2014, 08:19:18)
[GCC 4.9.2 20141101 (Red Hat 4.9.2-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class A(object):
... @property
... def __call__(self):
... raise AttributeError
...
>>> a = A()
>>> print(callable(a))
True
>>> a()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in __call__
AttributeError
$ jython
Jython 2.7b3+ (, Nov 3 2014, 11:02:14)
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.8.0_40
Type "help", "copyright", "credits" or "license" for more information.
>>> class A(object):
... @property
... def __call__(self):
... raise AttributeError
...
>>> a = A()
>>> print(callable(a))
True
>>> a()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in __call__
AttributeError
$ pypy
Python 2.7.8 (a980ebb26592ed26706cd33a4e05eb45b5d3ea09, Sep 24 2014, 07:41:52)
[PyPy 2.4.0 with GCC 4.9.1 20140912 (Red Hat 4.9.1-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>> class A(object):
.... @property
.... def __call__(self):
.... raise AttributeError
....
>>>> a = A()
>>>> print(callable(a))
True
>>>> a()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in __call__
AttributeError |
|