Message133362
> Devs are aware that there is an exception to the general rule
> for the 'for' clause. There is a technical reason why the
> exception is possible, though I have forgotten it.
It is best understood when thinking about a gexexp that
gets run long after is created:
ge = (result_exp(loop_var) for loop_var in iter_exp)
The idea was to have the body of the iterator expression, iter_exp, fail early, before the generator is run and while the local context is still set=up and available:
ge = (1/0 for i in pow('a', 'b'))
We want the TypeError for pow to be raised immediately. And if a valid expression were evaluated, we would want the body's ZeroDivisionError to be raised only when the generator is invoked using next(ge()).
In the former case, the local context is still available. In the latter case, it could be long gone. |
|
Date |
User |
Action |
Args |
2011-04-09 00:42:52 | rhettinger | set | recipients:
+ rhettinger, terry.reedy, eric.araujo, Trundle, jonathan.hartley, daniel.urban, docs@python, mjs0 |
2011-04-09 00:42:52 | rhettinger | set | messageid: <1302309772.6.0.910712882813.issue11796@psf.upfronthosting.co.za> |
2011-04-09 00:42:51 | rhettinger | link | issue11796 messages |
2011-04-09 00:42:51 | rhettinger | create | |
|