Support Assignment Expression ("walrus" operator) syntax
See original GitHub issueAssignment Expressions are a new feature added with Python 3.8. Currently, the VS Code Python Extension auto-corrects this syntax into invalid syntax, i.e. the colon is shifted left to be positioned on the right-most end of the assignee in the expression (to fit with “normal” colon usage in Python), putting a space between itself and the equal sign, forcing the user to Ctrl-Z the change each time.
For example, the line if (x := re.search(some_str)):
becomes if (x: = re.search(some_str)):
after pressing enter:
The requested feature would be to prevent this auto-correction.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:23
- Comments:11 (6 by maintainers)
Top Results From Across the Web
The Walrus Operator: Python 3.8 Assignment Expressions
The walrus operator is a new syntax that is only available in Python 3.8 and later. This means that any code you write...
Read more >What's New In Python 3.8 — Python 3.11.1 documentation
There is new syntax := that assigns values to variables as part of a larger expression. It is affectionately known as “the walrus...
Read more >How to use the assignment expression/walrus operator (:=)
A cool new feature called assignment expression was introduced in PEP572 in Python 3.8. Assignment expression uses operator := to assign the value...
Read more >Python walrus operator (Assignment Expression) - Like Geeks
Walrus operator is a special type of operator that got introduced with Python 3.8. This operator provides a way of assigning variables within...
Read more >using walrus operator in Python - ZetCode
The walrus operator creates an assignment expression. The operator allows us to assign a value to a variable inside a Python expression.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I just tried this with the black formatter and it seems to format things correctly now. I use format on save though, not format on type. I do have Jedi enabled since that is the default.
This no longer seems to be an issue. If you do face it again, please file a new bug report so we can investigate. Thanks!