This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients Trundle, daniel.urban, docs@python, eric.araujo, jonathan.hartley, mjs0, rhettinger, terry.reedy
Date 2011-04-09.00:42:51
SpamBayes Score 3.885861e-07
Marked as misclassified No
Message-id <1302309772.6.0.910712882813.issue11796@psf.upfronthosting.co.za>
In-reply-to
Content
> 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.
History
Date User Action Args
2011-04-09 00:42:52rhettingersetrecipients: + rhettinger, terry.reedy, eric.araujo, Trundle, jonathan.hartley, daniel.urban, docs@python, mjs0
2011-04-09 00:42:52rhettingersetmessageid: <1302309772.6.0.910712882813.issue11796@psf.upfronthosting.co.za>
2011-04-09 00:42:51rhettingerlinkissue11796 messages
2011-04-09 00:42:51rhettingercreate