PyCQA / pycodestyle

Simple Python style checker in one Python file
https://pycodestyle.pycqa.org
Other
5.01k stars 755 forks source link

E202 complains about meaningful space before parenthesis in f-strings debug expressions #1250

Closed nj-vs-vh closed 1 month ago

nj-vs-vh commented 1 month ago

Consider the following code using debug-expressions in f-strings. Here's the PEP that seeks to retroactively codify them and gives some links to their description.

var = 123
print(f"{var=}")
print(f"{var = }")

It produces the following output:

var=123
var = 123

As one can see, the spaces around the "=" sign are not a code formatting choice, but rather a part of the debug format. Hence, pycodestyle should probably ignore them. However, it currently thinks that it's a formatting error:

mre.py:3:13: E251 unexpected spaces around keyword / parameter equals
mre.py:3:15: E202 whitespace before '}'
mre.py:3:15: E251 unexpected spaces around keyword / parameter equals

I am extensively using these expressions in many projects and having to manually ignore E202 and E251 every time is a bit of a hassle!

asottile commented 1 month ago

please search for duplicates there are several exact ones!