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

Anders Kaseorg report at bugs.python.org
Thu Jul 22 19:53:33 CEST 2010


Anders Kaseorg <andersk at mit.edu> added the comment:

Antoine: That’s true.

Amaury: See my original bug description (“This is reasonable advice for writing an iterator class, but terrible advice for writing a container class…”), and my other comments.

There is nothing wrong with explaining how to write an iterator, but the explanation needs to make clear that this is _not_ how you write a container.  Currently the section opens with a misleading motivation (“By now you have probably noticed that most container objects can be looped over using a for statement”), but it does actually not explain how to write a container at all.  So I proposed some language and an example to fix that.

----------

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


More information about the Python-bugs-list mailing list