Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Apply suggestions from code review
  • Loading branch information
JelleZijlstra authored Oct 3, 2022
commit 4d0a933e94c28d60b973766b340f48e54fb38d4b
6 changes: 3 additions & 3 deletions Doc/reference/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1767,9 +1767,9 @@ Or, when processing a file stream in chunks:
process(chunk)

Assignment expressions must be surrounded by parentheses when used
as sub-expressions in subscript, slicing, conditional, lambda,
keyword-argument, generator, and comprehension-if expressions. They
can only be used as is in if and while statements and in decorators.
as sub-expressions in slicing, conditional, lambda,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unparenthesized assignment expressions in slices were implemented in #23317, so they are allowed since 3.10. Also, assignment expression need to parenthesized in assert and with statements.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unparenthesized walruses are allowed in index expressions but not slices. This is current 3.12:

>>> x[y:=3]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
>>> x[y:=3:z:=4]
  File "<stdin>", line 1
    x[y:=3:z:=4]
          ^
SyntaxError: invalid syntax

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct! I mixed up indexes/slices. Sorry!

keyword-argument, and comprehension-if expressions. They
can be used unparenthesized in all other places, including ``if`` and ``while`` statements.
Comment thread
JelleZijlstra marked this conversation as resolved.
Outdated

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