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

E203 conflicts with formatter (and black) #8752

Closed
bersbersbers opened this issue Nov 18, 2023 · 3 comments · Fixed by #8838
Closed

E203 conflicts with formatter (and black) #8752

bersbersbers opened this issue Nov 18, 2023 · 3 comments · Fixed by #8838
Assignees
Labels
bug Something isn't working

Comments

@bersbersbers
Copy link
Contributor

Rule E203 still conflicts with ruff's own formatter:

bug.py

x = [1, 2, 3]
x[len(x) :]

bug.bat

@echo off
pip install black==23.11.0 ruff==0.1.6
black bug.py
ruff format --isolated bug.py
ruff check --isolated --preview --select E203 --fix bug.py
ruff format --isolated bug.py
ruff check --isolated --preview --select E203 --fix bug.py
ruff format --isolated bug.py

Output:

All done! ✨ 🍰 ✨
1 file left unchanged.
1 file left unchanged
Found 1 error (1 fixed, 0 remaining).
1 file reformatted
Found 1 error (1 fixed, 0 remaining).
1 file reformatted

Somewhat related to #7259 (but 0.1.5 behaves the same way, so likely #8654 did not break this, but instead should be extended to one-sided slices)

Potentially relevant for #7993

@charliermarsh charliermarsh added the bug Something isn't working label Nov 18, 2023
@charliermarsh
Copy link
Member

Is this consistent with PEP 8, though? I feel like it's in conflict with the PEP 8 guidelines (which is fine for the formatter, but the intent of the pycodestyle rules is to enforce PEP 8). Now I'm wondering if we should instead just mark the rule as incompatible, rather than trying to make it compatible with the formatter.

@bersbersbers
Copy link
Contributor Author

PEP8 doesn't say anything about this.

Exception: when a slice parameter is omitted, the space is omitted

This does not apply in our case: it concerns the space after the colon (where the parameter is omitted), not before the colon.

How exactly you solve this, I don't really care. Using black right now, I'm preparing the switch to ruffs formatter and ideally, you would make that as painless as possible :) Disabling rules for this is fine. (Is there a selector to ignore all formatter-incompatible rules?)

@Blumenkind111
Copy link

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 and ruff . --fix always removes it.

xmatthias added a commit to freqtrade/freqtrade that referenced this issue May 13, 2024
Incompatible with ruff ...
astral-sh/ruff#8752
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants