gh-138294: Fix Misleading error for ((a) := 1)#138627
gh-138294: Fix Misleading error for ((a) := 1)#138627dbXD320 wants to merge 5 commits intopython:mainfrom
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 :) |
…e-138294.abcd12.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
|
@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.
Thanks a lot @dbXD320! The PR looks good! 🚀
Left just one comment for where I think the test should go.
| 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.
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.
@dbXD320 You can add a new section like this:
cpython/Lib/test/test_syntax.py
Line 2471 in 921f61b
|
This PR is stale because it has been open for 30 days with no activity. |
This PR fixes a corner-case in assignment expressions (walrus operator :=) where using parentheses around a target name incorrectly compiles, e.g., ((x) := 1).