Mark Dickinson added the comment:

The outer for loop in a generator expression is evaluated immediately; 
everything after that is evaluated lazily. This was a deliberate design choice: 
see https://www.python.org/dev/peps/pep-0289/#early-binding-versus-late-binding 
for some rationale. This explains why you're able to access "B". The inability 
to access "C" is due to the usual rule for Python scope resolution: class 
scopes are skipped when examining nested scopes.

The early evaluation of the outermost for is covered in the docs, here: 
https://docs.python.org/2/reference/expressions.html#generator-expressions

"""
However, the leftmost for clause is immediately evaluated, so that an error 
produced by it can be seen before any other possible error in the code that 
handles the generator expression.
"""

So this behaviour is by design, though there may be a doc issue here. Changing 
components and versions accordingly.

----------
assignee:  -> docs@python
components: +Documentation -Interpreter Core
nosy: +docs@python, mark.dickinson
versions: +Python 3.6 -Python 3.2, Python 3.3, Python 3.4

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26951>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to