[issue8376] Tutorial offers dangerous advice about iterators: “__iter__() can just return self”

R. David Murray report at bugs.python.org
Thu Jul 13 08:29:41 EDT 2017


R. David Murray added the comment:

I just had a colleague get confused about the container returning self, and he was referring to the iterator protocol docs at https://docs.python.org/3.6/library/stdtypes.html#iterator.__iter__.  If you don't read that section with your thinking cap firmly in place it is easy to get confused about what "the iterator itself" means there.  I think it would be beneficial to add a sentence about the iterator state needing to be independent for each iterator returned by the *container's* __iter__.  A similar sentence in the tutorial might be all that is needed as well.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8376>
_______________________________________


More information about the Python-bugs-list mailing list