Skip to content
New issue

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

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

Already on GitHub? # to your account

E203: false positive in f-string using formatting #12023

Closed
JaRoSchm opened this issue Jun 25, 2024 · 1 comment · Fixed by #12024
Closed

E203: false positive in f-string using formatting #12023

JaRoSchm opened this issue Jun 25, 2024 · 1 comment · Fixed by #12024
Assignees
Labels
bug Something isn't working

Comments

@JaRoSchm
Copy link
Contributor

Hi,

this example raises E203 (ruff 0.4.10) although it clearly shouldn't in my opinion:

x = 3.14159
print(f"{x = :.2f}")

Output of ruff check --select E203 --preview:

test.py:2:13: E203 [*] Whitespace before ':'
  |
1 | x = 3.14159
2 | print(f"{x = :.2f}")
  |             ^ E203
  |
  = help: Remove whitespace before ':'

However, removing the whitespace changes the output from x = 3.14 to x =3.14.

@dhruvmanila
Copy link
Member

Yeah, I agree. I remember updating the rules to avoid checking inside f-strings when I added support for it, I guess I must've missed this one. Thank you for reporting!

@dhruvmanila dhruvmanila added the bug Something isn't working label Jun 25, 2024
@dhruvmanila dhruvmanila self-assigned this Jun 25, 2024
dhruvmanila added a commit that referenced this issue Jun 25, 2024
## Summary

This PR fixes a bug where Ruff would raise `E203` for f-string debug
expression. This isn't valid because whitespaces are important for debug
expressions.

fixes: #12023

## Test Plan

Add test case and make sure there are no snapshot changes.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants