[issue31126] dict comprehension shouldn't raise UnboundLocalError
Eryk Sun
report at bugs.python.org
Sun Aug 6 19:07:21 EDT 2017
Eryk Sun added the comment:
It's consistent with the behavior of generator expressions:
Variables used in the generator expression are evaluated lazily
when the __next__() method is called for the generator object
(in the same fashion as normal generators). 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. Subsequent for
clauses cannot be evaluated immediately since they may depend
on the previous for loop. For example: (x*y for x in range(10)
for y in bar(x)).
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue31126>
_______________________________________
More information about the Python-bugs-list
mailing list