mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-111944: Add assignment expression parentheses requirements (#111977)
gh-111944: Clarify where assignment expressions require ()s Augment the list of places where parentheses are required around assignnment statements. In particular, 'a := 0' and 'a = b := 1' are syntax errors.
This commit is contained in:
parent
d7cef7bc7e
commit
9a2f25d374
1 changed files with 5 additions and 4 deletions
|
|
@ -1781,10 +1781,11 @@ 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.
|
||||
Assignment expressions must be surrounded by parentheses when
|
||||
used as expression statements and when used as sub-expressions in
|
||||
slicing, conditional, lambda,
|
||||
keyword-argument, and comprehension-if expressions and
|
||||
in ``assert``, ``with``, and ``assignment`` statements.
|
||||
In all other places where they can be used, parentheses are not required,
|
||||
including in ``if`` and ``while`` statements.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue