Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 8 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Doc/reference/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,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 subscript, slicing, conditional, lambda,
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved
keyword-argument, generator, and comprehension-if expressions. They
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved
can only be used as is in if and while statements and in decorators.
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved

.. versionadded:: 3.8
See :pep:`572` for more details about assignment expressions.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Document some places where an assignment expression needs parentheses.