[issue14845] list(<generator expression>) != [<list comprehension>]

Terry J. Reedy report at bugs.python.org
Fri May 18 22:50:40 CEST 2012


Terry J. Reedy <tjreedy at udel.edu> added the comment:

It has been noted elsewhere (but I cannot find it) that 1) an uncaught StopIteration raised in an expression *within* a genexp is indistinguishable from the StopIteration raised *by* the genexp upon normal termination; and 2) this makes genexps different from otherwise equivalent comprehensions. The statement in PEP289 does not address this exceptional case.

Raymond, do you want to revise your PEP to mention this?

PEPs are, as their name says, proposals that express intention, not result, and especially not the result after continued patching. We do not usually usually go back and revise PEPs after they have been implemented. It would be an endless task. Hence, they are not current 'documentation' unless unless specifically referred from the docs. This one is not so referenced.

Perhaps PEP 0 should say that " Finished PEPs (done, implemented in code repository)" are historical documents and not current documentation.

I checked the entries for comprehensions and generator expressions and they do not claim equivalence, but do (briefly) describe the actual behavior. However, it is easy to miss that the entry in 5.2.8. Generator expressions implies the two facts above. Perhaps we should explicitly say something like:

If *expression* raises StopIteration, it will not be distinguished from the StopIteration raised upon normal termination of the generator, and it will make the generator expression act differently from the otherwise equivalent comprehension.

----------
assignee:  -> docs at python
components: +Documentation -Interpreter Core
nosy: +docs at python, rhettinger, terry.reedy

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


More information about the Python-bugs-list mailing list