GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-86482: Document assignment expression need for ()s by terryjreedy · Pull Request #23291 · python/cpython

Conversation

@terryjreedy

@terryjreedy terryjreedy commented Nov 15, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

The list should cover most places where an assignment sub-expression
must be wrapped in parentheses. Judging from the statement docs,
only a couple of statements do not require that they be wrapped.

  • Issue: Walrus Operator in list index #86482

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
terryjreedy added 2 commits November 15, 2020 02:38
@terryjreedy
bpo-42316: Document assignment expression need for ()s
ff66b33
The list should cover most places where an assignment sub-expression
must be wrapped in parentheses. Judging from the statement docs,
only a couple of statements do not require that they be wrapped.
@terryjreedy
Add 'be'
09653d7
@terryjreedy terryjreedy added docs Documentation in the Doc dir needs backport to 3.8 labels Nov 15, 2020
@terryjreedy
terryjreedy requested a review from gvanrossum November 15, 2020 07:44
@terryjreedy terryjreedy self-assigned this Nov 15, 2020
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Nov 15, 2020
@bedevere-bot bedevere-bot added the awaiting core review label Nov 15, 2020
terryjreedy
terryjreedy commented Nov 15, 2020
View reviewed changes
Comment thread Doc/reference/expressions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

gvanrossum
gvanrossum reviewed Nov 16, 2020
View reviewed changes
Comment thread Doc/reference/expressions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Nov 16, 2020
bpo-42374: Allow unparenthesized walrus in genexps #23319
Merged
bpo-42316: Allow unparenthesized walrus operator in indexes #23317
Merged
@lysnikolaou

lysnikolaou commented Nov 16, 2020

Copy link
Copy Markdown
Member

This PR probably needs to be updated to reflect the recent changes introduced in #23317 and #23319. Sorry @terryjreedy!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@terryjreedy

terryjreedy commented Nov 17, 2020

Copy link
Copy Markdown
Member Author

These are changes I hoped to be able to make ;-). I will add the new in 3.10 item for indexes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Dec 18, 2020

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Dec 18, 2020
@ambv ambv removed the needs backport to 3.8 label May 4, 2021
@vbarbaresi vbarbaresi mentioned this pull request Oct 24, 2021
Error trying to format line with parameter assignment and generator psf/black#2551
Closed
@JelleZijlstra
Merge branch 'main' into walrus
43ed4f5
JelleZijlstra
JelleZijlstra reviewed Apr 5, 2022
View reviewed changes

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@terryjreedy are you still interested in landing this? A few older comments were never applied.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/reference/expressions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/reference/expressions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@terryjreedy terryjreedy removed their assignment Apr 6, 2022
@terryjreedy

terryjreedy commented Apr 6, 2022

Copy link
Copy Markdown
Member Author

I somehow missed finishing this and would like it updated and merged. The doc is needed; someone just posted code to pydev that was missing required ()s. However, I just discovered that I have been recently de-authorized from merging anything. Jelle, you have been doing great with doc patches, so it would be fine with me if you finished this without waiting for that problem to be fixed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra

JelleZijlstra commented Apr 6, 2022

Copy link
Copy Markdown
Member

I have been recently de-authorized from merging anything

Pablo had turned off merges for everyone during the 3.11.0a7 release, but merges are allowed now again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra JelleZijlstra self-assigned this Apr 6, 2022
@serhiy-storchaka serhiy-storchaka added needs backport to 3.10 needs backport to 3.11 only security fixes and removed needs backport to 3.9 labels May 20, 2022
@ezio-melotti ezio-melotti removed the CLA signed label Jul 13, 2022
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jul 31, 2022
JelleZijlstra
JelleZijlstra reviewed Oct 3, 2022
View reviewed changes
Comment thread Doc/reference/expressions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/reference/expressions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/reference/expressions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra
Apply suggestions from code review
4d0a933
JelleZijlstra
JelleZijlstra reviewed Oct 3, 2022
View reviewed changes
Comment thread Doc/reference/expressions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra
Update Doc/reference/expressions.rst
ae4788e
JelleZijlstra
JelleZijlstra approved these changes Oct 3, 2022
View reviewed changes

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This looks good to me now. I'll merge it in a few days unless other people on the PR have more feedback.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Oct 3, 2022
JelleZijlstra
JelleZijlstra reviewed Oct 3, 2022
View reviewed changes
Comment thread Doc/reference/expressions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra
Update Doc/reference/expressions.rst
07b9fe5
@gvanrossum

gvanrossum commented Oct 3, 2022

Copy link
Copy Markdown
Member

I'm fine with documenting this more precisely, and the wording here looks fine. However, I don't have the time to review the facts -- I hope that Lysandros and Jelle can make sure that the claim made in the text is true (or as close to true as reasonable without spelling out the entire grammar).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lysnikolaou
lysnikolaou reviewed Oct 3, 2022
View reviewed changes
Comment thread Doc/reference/expressions.rst
process(chunk)

Assignment expressions must be surrounded by parentheses when used
as sub-expressions in slicing, conditional, lambda,

@lysnikolaou lysnikolaou Oct 3, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JelleZijlstra JelleZijlstra Oct 3, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lysnikolaou lysnikolaou Oct 3, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
JelleZijlstra
JelleZijlstra reviewed Oct 3, 2022
View reviewed changes
Comment thread Doc/reference/expressions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra
Update Doc/reference/expressions.rst
a9d94bf
@JelleZijlstra
JelleZijlstra merged commit 2b5f136 into python:main Oct 6, 2022
@miss-islington

miss-islington commented Oct 6, 2022

Copy link
Copy Markdown
Contributor

Thanks @terryjreedy for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting merge label Oct 6, 2022
@bedevere-bot

bedevere-bot commented Oct 6, 2022

Copy link
Copy Markdown

GH-97986 is a backport of this pull request to the 3.11 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Oct 6, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 6, 2022
@terryjreedy @miss-islington
pythongh-86482: Document assignment expression need for ()s (pythonGH…
cc41183
…-23291)

Co-authored-by: Jelle Zijlstra <[email protected]>
(cherry picked from commit 2b5f136)

Co-authored-by: Terry Jan Reedy <[email protected]>
@bedevere-bot

bedevere-bot commented Oct 6, 2022

Copy link
Copy Markdown

GH-97987 is a backport of this pull request to the 3.10 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 label Oct 6, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 6, 2022
@terryjreedy @miss-islington
pythongh-86482: Document assignment expression need for ()s (pythonGH…
90ebcbc
…-23291)

Co-authored-by: Jelle Zijlstra <[email protected]>
(cherry picked from commit 2b5f136)

Co-authored-by: Terry Jan Reedy <[email protected]>
@Brando753 Brando753 mannequin mentioned this pull request Oct 6, 2022
Walrus Operator in list index #86482
Closed
miss-islington added a commit that referenced this pull request Oct 6, 2022
@miss-islington @terryjreedy
gh-86482: Document assignment expression need for ()s (GH-23291)
4aa2ebc
Co-authored-by: Jelle Zijlstra <[email protected]>
(cherry picked from commit 2b5f136)

Co-authored-by: Terry Jan Reedy <[email protected]>
miss-islington added a commit that referenced this pull request Oct 6, 2022
@miss-islington @terryjreedy
gh-86482: Document assignment expression need for ()s (GH-23291)
b7487df
Co-authored-by: Jelle Zijlstra <[email protected]>
(cherry picked from commit 2b5f136)

Co-authored-by: Terry Jan Reedy <[email protected]>
carljm added a commit to carljm/cpython that referenced this pull request Oct 6, 2022
@carljm
Merge branch 'main' into dictwatch
e5d2169
* main:
  fixes pythongh-96078: os.sched_yield release the GIL while calling sched_yield(2). (pythongh-97965)
  pythongh-65961: Do not rely solely on `__cached__` (pythonGH-97990)
  pythongh-97850: Remove the open issues section from the import reference (python#97935)
  Docs: pin sphinx-lint (pythonGH-97992)
  pythongh-94590: add signatures to operator itemgetter, attrgetter, methodcaller (python#94591)
  Add Pynche's move to the What's new in 3.11 (python#97974)
  pythongh-97781: Apply changes from importlib_metadata 5. (pythonGH-97785)
  pythongh-86482: Document assignment expression need for ()s (python#23291)
  pythongh-97943: PyFunction_GetAnnotations should return a borrowed reference. (python#97949)
  pythongh-94808: Coverage: Test that maximum indentation level is handled (python#95926)
carljm added a commit to carljm/cpython that referenced this pull request Oct 8, 2022
@carljm
Merge branch 'main' into typewatch
415ed49
* main:
  pythonGH-97002: Prevent `_PyInterpreterFrame`s from backing more than one `PyFrameObject` (pythonGH-97996)
  pythongh-97973: Return all necessary information from the tokenizer (pythonGH-97984)
  fixes pythongh-96078: os.sched_yield release the GIL while calling sched_yield(2). (pythongh-97965)
  pythongh-65961: Do not rely solely on `__cached__` (pythonGH-97990)
  pythongh-97850: Remove the open issues section from the import reference (python#97935)
  Docs: pin sphinx-lint (pythonGH-97992)
  pythongh-94590: add signatures to operator itemgetter, attrgetter, methodcaller (python#94591)
  Add Pynche's move to the What's new in 3.11 (python#97974)
  pythongh-97781: Apply changes from importlib_metadata 5. (pythonGH-97785)
  pythongh-86482: Document assignment expression need for ()s (python#23291)
  pythongh-97943: PyFunction_GetAnnotations should return a borrowed reference. (python#97949)
mpage pushed a commit to mpage/cpython that referenced this pull request Oct 11, 2022
@terryjreedy @JelleZijlstra @mpage
pythongh-86482: Document assignment expression need for ()s (python#2…
ff0d621
…3291)

Co-authored-by: Jelle Zijlstra <[email protected]>
pablogsal pushed a commit that referenced this pull request Oct 22, 2022
@miss-islington @terryjreedy @pablogsal
gh-86482: Document assignment expression need for ()s (GH-23291)
cc10a8e
Co-authored-by: Jelle Zijlstra <[email protected]>
(cherry picked from commit 2b5f136)

Co-authored-by: Terry Jan Reedy <[email protected]>
@terryjreedy
terryjreedy deleted the walrus branch December 17, 2023 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@JelleZijlstra JelleZijlstra JelleZijlstra approved these changes
@gvanrossum gvanrossum gvanrossum left review comments
@lysnikolaou lysnikolaou lysnikolaou left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@JelleZijlstra JelleZijlstra

Labels

docs Documentation in the Doc dir

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@terryjreedy @lysnikolaou @JelleZijlstra @gvanrossum @miss-islington @bedevere-bot @ambv @serhiy-storchaka @the-knights-who-say-ni @ezio-melotti
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.