-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-138294: Fix Misleading error for ((a) := 1) #138627
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
base: main
Are you sure you want to change the base?
Conversation
|
@pablogsal @lysnikolaou Hi, I’ve added the grammar change for raising a SyntaxError when a walrus target is parenthesized. |
It should go in test_syntax. Find a zone where we test similar errors and add a new one respecting the structure of the other examples. If you are not sure just put it somewhere you thing is good and we can guide you from there :) |
Misc/NEWS.d/next/Core_and_Builtins/2025-09-08-12-30-00.gh-issue-138294.abcd12.rst
Outdated
Show resolved
Hide resolved
…e-138294.abcd12.rst Co-authored-by: Stan Ulbrych <[email protected]>
|
@pablogsal I’ve added the test in test_syntax.py. Please review it and let me know if any adjustments are needed. |
lysnikolaou
left a comment
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.
Thanks a lot @dbXD320! The PR looks good! 🚀
Left just one comment for where I think the test should go.
Lib/test/test_syntax.py
Outdated
| def test_parenthesized_named_expression_target(self): | ||
| self._check_error( | ||
| "((a) := 1)", | ||
| "cannot parenthesize target name in assignment expression") | ||
|
|
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.
I think it'd be best if this went in the docstring at the top of the file instead of a separate test. It can probably go at the very bottom of that docstring with a short description of the error being tested, something along the lines of Invalid parenthesization inside assignment expressions.
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.
@dbXD320 You can add a new section like this:
cpython/Lib/test/test_syntax.py
Line 2471 in 921f61b
| Invalid expressions in type scopes: |
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.
LGTM
thanks for applying my patch!
This PR fixes a corner-case in assignment expressions (walrus operator :=) where using parentheses around a target name incorrectly compiles, e.g., ((x) := 1).