[issue35224] PEP 572: Assignment Expressions

Nick Coghlan report at bugs.python.org
Mon Aug 5 00:32:26 EDT 2019


Nick Coghlan <ncoghlan at gmail.com> added the comment:

#37757 now has an associated PR adding the missing TargetScopeError cases: https://github.com/python/cpython/pull/15131

There's one case where it goes beyond what the PEP specifies: because the outermost iterable expression gets evaluated in a different scope from the rest of the comprehension, it just flat out prohibits the use of assignment expressions in comprehension iterable expressions.

This was one of the cases where we explicitly didn't want the CPython implementation behaviour to leak into the language specification (as name binding in the outermost iterable expression would create an unrelated binding in the containing scope, while name binding in other iterable expressions would rebind any conflicting iteration variable in the comprehension), so the current PR takes the more conservative path, and defers allowing name binding in the iterable expressions until a specific use case for doing so is presented).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35224>
_______________________________________


More information about the Python-bugs-list mailing list