-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
E203: conflicts with formatter #10041
Comments
I have the same issue: countries = ["Spain", "France", "UK", "Norway", "Iceland"]
print(f"{countries[:3]}")
print(f"{countries[1:4]}")
middle = len(countries) // 2
print(f"{countries[middle : middle + 3]}") # `ruff format --preview` add spaces here, byt `ruff --fix` removes spaces.
print(f"{countries[-3:]}") It started only since version |
This is because f-string formatting was added in preview in that release. This isn't the issue here but just clarifying that the problem was present before that version as well. You can try it out by keeping the expression outside the f-string: countries[middle : middle + 3] |
It might be difficult to fix I wonder if it's worth the struggle. To me it seems the main purpose of the rule related to |
Regarding
However, the rule disallows leading tabs or multiple spaces (which I think is in accordance with PEP8 although not explicitly mentioned). The rule's fix isn't as sophisticated as the formatter. It always removes the whitespace if it encounters multiple spaces or tabs that may disagree with the formatter). However, that's fine, because we only aim for formatted code not to raise lint errors but our fixes don't need to be properly formatted. The linter won't raise an error for your example if you only use one whitespace around the colons. |
Hi, I think there is another case, where it is not working and that is when we have multiple indices, like in pandas:
My example looks like this:
dataframe.loc[index + 1 :, "columnname"]
Ruff format
always adds the space andruff . --fix
always removes it.Originally posted by @Blumenkind111 in #8752 (comment)
Playground https://play.ruff.rs/de63f867-2176-4c27-b653-d0c3eb49754d
The text was updated successfully, but these errors were encountered: