This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ionelmc
Recipients Claudiu.Popa, belopolsky, christian.heimes, ethan.furman, ionelmc, jedwards, llllllllll, terry.reedy
Date 2015-04-18.10:30:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> This is exactly analogous to what you are seeing with __call__ and callable().

Your example is incorrect, __next__ is what makes an object iterable but not what makes an object have an iterator (what __iter__ does).

This correctly characterises the issue:

>>> class NonIter:
...     pass
>>> iter(NonIter())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NonIter' object is not iterable
>>> class DynamicNonIter:
...     has_iter = False
...     @property
...     def __iter__(self):
...         if self.has_iter:
...             from functools import partial
...             return partial(iter, [1, 2, 3])
...         else:
...             raise AttributeError("Not really ...")
>>> dni = DynamicNonIter()
>>> iter(dni)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'DynamicNonIter' object is not iterable
>>> dni.has_iter = True
>>> iter(dni)
<list_iterator object at 0x000000000362FF60>

Now, if this is possible for `iter`, why shouldn't it be possible for `callable`? 

I'm not opposed to writing a PEP but the issue with `callable` is the only one I'm aware of, and this seems too small in scope anyway.
Date User Action Args
2015-04-18 10:30:12ionelmcsetrecipients: + ionelmc, terry.reedy, belopolsky, christian.heimes, Claudiu.Popa, ethan.furman, llllllllll, jedwards
2015-04-18 10:30:12ionelmcsetmessageid: <>
2015-04-18 10:30:12ionelmclinkissue23990 messages
2015-04-18 10:30:12ionelmccreate