https://www.python.org/dev/peps/pep-0572/
E203 and E231 should be disabled for := in assignment expressions.
E701 as well
$ cat t.py
if x := 1:
print(x)
$ python3.8 t.py
1
$ python3.8 pycodestyle.py t.py
t.py:1:5: E203 whitespace before ':'
t.py:1:6: E231 missing whitespace after ':'
t.py:1:6: E701 multiple statements on one line (colon)
Please?
Looking forward to this feature too ! :)
E701 as well
$ cat t.py if x := 1: print(x) $ python3.8 t.py 1 $ python3.8 pycodestyle.py t.py t.py:1:5: E203 whitespace before ':' t.py:1:6: E231 missing whitespace after ':' t.py:1:6: E701 multiple statements on one line (colon)
After reading the PEP 572 (https://www.python.org/dev/peps/pep-0572/#syntax-and-semantics), it seems that the following syntax should be preferred:
if (x := 1):
print(x)
While the code behaviour will be the same, E701 will be fixed.
@AntoineSebert, I don't infer from the linked section (or anywhere in the PEP) that your example should be parenthesized. Also, no such check currently exists within pycodestyle, afaik.
Proper support for assignment expression has been suggested in #879. It is expected to be used like a normal binary operator surrounded by spaces.
@FichteFoll I don't know what to say, it's literally the first you see when you click the link, and it's also the subject of the 7 sections below that start with "Unparenthesized assignment expressions are prohibited [...]".
Do you have trouble accessing https://www.python.org ?
I checked again and the website worked fine, maybe some content is not available to you for whatever reason, or you are using a browser extension that somehow hides some of the content.
Concerning the inexisting pycodestyle check, it's normal: pycodestyle does not actually support assignments expressions.
@AntoineSebert those are the exceptional cases, they are permitted without parenthesization elsewhere. as you can see from my comment the code runs fine
@AntoineSebert, please make sure to quote the entire sentence, as you left out a very important restriction.
Unparenthesized assignment expressions are prohibited at the top level of an expression statement.
Compare this with the examples that explicitly use assignment expressions without parentheses in the expression for an if or while statement, as well as the valid example code that @asottile referred to in his first comment on this issue.
Regardless, spotting invalid use of assignment expressions resulting in invalid syntax (which there are multiple possibilities for) is not within pycodestyle's scope and should be left to a tool that actually parses the file for syntax errors, such as flake8/pyflakes.
is there a release date??
I tried writing my first walrus but pycodestyle-2.5.0 is flagging it. What version is this fix supposed to be in?
It hasn't been released yet.
Hi! Any updates on this? Or any plans to release a new version of package?
@sigmavirus24 can you help with this?
Can you guys please make a release with this fix? 3.8 is 4 months old now... and 3.9 is close.
Thanks for the great tool! Can we please get a new release for 3.8? Python projects are always having trouble to keep up with releases. Same with black, pipenv.... Why is that?
it's not so simple to "just release" and commenting here does not help us release faster -- if you want to help out please review open PRs and try the latest against codebases -- see also https://github.com/PyCQA/pycodestyle/issues/899
Most helpful comment
it's not so simple to "just release" and commenting here does not help us release faster -- if you want to help out please review open PRs and try the latest against codebases -- see also https://github.com/PyCQA/pycodestyle/issues/899