On 21 August 2016 at 16:02, eryk sun <eryk...@gmail.com> wrote: > On Sun, Aug 21, 2016 at 5:27 AM, Chris Angelico <ros...@gmail.com> wrote: >> Hmm. It would somehow need to be recognized as "not iterable". I'm not >> sure how this detection is done; is it based on the presence/absence >> of __iter__, or is it by calling that method and seeing what comes >> back? If the latter, then sure, an __iter__ that raises would cover >> that. > > PyObject_GetIter calls __iter__ (i.e. tp_iter) if it's defined. To get > a TypeError, __iter__ can return an object that's not an iterator, > i.e. an object that doesn't have a __next__ method (i.e. tp_iternext).
I believe Chris's concern was that "isintance(obj, collections.abc.Iterable)" would still return True. That's actually a valid concern, but Python 3.6 generalises the previously __hash__ specific "__hash__ = None" anti-registration mechanism to other protocols, including __iter__: https://hg.python.org/cpython/rev/72b9f195569c Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/