Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positives when using white space around = in f-string debug format. #1258

Closed
WarrenWeckesser opened this issue Aug 20, 2024 · 1 comment

Comments

@WarrenWeckesser
Copy link

WarrenWeckesser commented Aug 20, 2024

With this file:

x = 123
print(f'{ x = }')

pycodestyle 2.12.1 gives this output:

$ pycodestyle -v foo.py 
checking foo.py
foo.py:2:10: E201 whitespace after '{'
foo.py:2:12: E251 unexpected spaces around keyword / parameter equals
foo.py:2:14: E202 whitespace before '}'
foo.py:2:14: E251 unexpected spaces around keyword / parameter equals

Those spaces should not be reported as problems. Spaces in front of x and around = in that string are significant. The = format was designed and implemented to allow such spaces. To quote from python/cpython#80998,

Finally, and this is the best part: what if you want whitespace around
the equals sign? Well, to the left is no problem; whitespace is preserved
from the original text inside the curly braces:
f"{ chr(65) =}" => " chr(65) ='A'"
But we also explicitly permit, and preserve, whitespace after the
equals sign:
f"{chr(65) = }" => "chr(65) = 'A'"

@asottile
Copy link
Member

please search for duplicates!

@PyCQA PyCQA locked as off-topic and limited conversation to collaborators Aug 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants