Skip to content

Commit 041d821

Browse files
committed
Add a note on assignment expressions
1 parent f6cf726 commit 041d821

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Doc/reference/expressions.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -829,13 +829,15 @@ Subsequent :keyword:`!for` clauses and any filter condition in the
829829
leftmost :keyword:`!for` clause cannot be evaluated in the enclosing scope as
830830
they may depend on the values obtained from the leftmost iterable.
831831

832-
TODO: PEP 572:
833-
..due to a limitation in CPython’s symbol table analysis process, the reference implementation raises SyntaxError for all uses of named expressions inside comprehension iterable expressions, rather than only raising them when the named expression target conflicts with one of the iteration variables in the comprehension. This could be revisited given sufficiently compelling examples, but the extra complexity needed to implement the more selective restriction doesn’t seem worthwhile for purely hypothetical use cases.
834-
835832
To ensure the comprehension always results in a container of the appropriate
836833
type, ``yield`` and ``yield from`` expressions are prohibited in the implicitly
837834
nested scope.
838835

836+
:ref:`Assignment expressions <assignment-expressions>` are not allowed
837+
inside comprehension iterable expressions (that is, the expressions after
838+
the :keyword:`!in` keyword), nor anywhere within comprehensions that
839+
appear directly in a class definition.
840+
839841
.. versionchanged:: 3.8
840842
``yield`` and ``yield from`` prohibited in the implicitly nested scope.
841843

0 commit comments

Comments
 (0)