gh-86482: Document assignment expression need for ()s (#23291)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
Terry Jan Reedy 2022-10-06 15:24:17 -04:00 committed by GitHub
parent 6bfb0be804
commit 2b5f1360ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View file

@ -1766,6 +1766,13 @@ Or, when processing a file stream in chunks:
while chunk := file.read(9000):
process(chunk)
Assignment expressions must be surrounded by parentheses when used
as sub-expressions in slicing, conditional, lambda,
keyword-argument, and comprehension-if expressions
and in ``assert`` and ``with`` statements.
In all other places where they can be used, parentheses are not required,
including in ``if`` and ``while`` statements.
.. versionadded:: 3.8
See :pep:`572` for more details about assignment expressions.