[Python-ideas] Generators are iterators
Stephen J. Turnbull
stephen at xemacs.org
Tue Dec 16 06:48:23 CET 2014
Juancarlo AƱez writes:
> Most newcomers to programming take a while to grok complex control
> flows, and what's happening here is too complex even for Python
> contributors.
As I understand Raymond's point, what is happening here is *not*
particularly complex (I don't see it as complex myself, anyway). It's
simply an obscure (because rare) and obvious (once you know about it)
consequence of two simple design decisions: "exceptions bubble" and
"iterator termination is signaled with an exception". That obscurity
is compounded by the fact that a programmer error will pass silently.
(There must be a theorem that says that in any Turing complete
language some errors will pass silently!)
In the case of *generators* silently ignoring an error is unnecessary,
and PEP 479 fixes that one case, at a cost of breaking a useful idiom
in some functions.
For iterators in general, I suppose we could add a flag to checkers to
look for function calls inside iterators, and warn the user to check
for the potential for spuriously raising StopIteration. (I doubt
that's a great idea, but it could be done.)
More information about the Python-ideas
mailing list