Ethan Furman added the comment:

Python 3.4.0 (default, Apr 11 2014, 13:05:18) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
--> class NonIter:
...    pass
... 
--> list(iter(NonIter()))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NonIter' object is not iterable

--> class MaybeIter:
...    @property
...    def __next__(self):
...       raise AttributeError
...    def __iter__(self):
...       return self
... 
--> iter(MaybeIter())
<__main__.MaybeIter object at 0xb6a5da2c>  # seems to work

--> list(iter(MaybeIter()))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in __next__
AttributeError

This is exactly analogous to what you are seeing with __call__ and callable().

I am not opposed to "fixing" callable(), I'm opposed to fixng only callable().  
If you want to have the descriptor protocol be given more weight in dealing 
with special methods (aka magic methods aka dunder methods) then be thorough.  
Find all (or at least most ;) of the bits and pieces that rely on these __xxx__ 
methods, write a PEP explaining why this extra effort should be undertaken, get 
a reference implementation together so the performance hit can be measured, and 
then make the proposal.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23990>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to