report at bugs
May 18, 2012, 1:50 PM
Post #5 of 7
Terry J. Reedy <tjreedy [at] udel> added the comment:
[issue14845] list(<generator expression>) != [<list comprehension>]
[In reply to]
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] pytho
components: +Documentation -Interpreter Core
nosy: +docs [at] pytho, rhettinger, terry.reedy
Python tracker <report [at] bugs>
Python-bugs-list mailing list