[docs] [issue26951] Unintuitive error when using generator expression in class property

Mark Dickinson report at bugs.python.org
Wed May 4 14:31:35 EDT 2016


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 at python
components: +Documentation -Interpreter Core
nosy: +docs at python, mark.dickinson
versions: +Python 3.6 -Python 3.2, Python 3.3, Python 3.4

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


More information about the docs mailing list