question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support Assignment Expression ("walrus" operator) syntax

See original GitHub issue

Assignment 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:

walrus_bug

The requested feature would be to prevent this auto-correction.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:23
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
dscottboggscommented, Jan 8, 2020

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.

0reactions
luabudcommented, Apr 28, 2021

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found