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

Rule E203 conflicts with formatter #8642

Closed
ofek opened this issue Nov 13, 2023 · 6 comments · Fixed by #8654
Closed

Rule E203 conflicts with formatter #8642

ofek opened this issue Nov 13, 2023 · 6 comments · Fixed by #8654
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@ofek
Copy link
Contributor

ofek commented Nov 13, 2023

Running the formatter on

release_lines = history_file_lines[history_file_lines.index('## Unreleased') + 1: -1]

produces

release_lines = history_file_lines[history_file_lines.index('## Unreleased') + 1 : -1]

which then fails the rule

scripts\utils.py:22:85: E203 Whitespace before ':'

Is the fix simply to document that here? https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules

@charliermarsh
Copy link
Member

I will add it to that list, though there's an open issue to fix the rule to allow this: #7259.

@charliermarsh
Copy link
Member

I decided to just fix it instead.

@ofek
Copy link
Contributor Author

ofek commented Nov 13, 2023

Oh nice that's much better, thanks!

charliermarsh added a commit that referenced this issue Nov 13, 2023
…ation` (`E203`) (#8654)

## Summary

This PR makes `whitespace-before-punctuation` (`E203`) compatible with
the formatter by relaxing the rule a bit, as compared to the pycodestyle
implementation. It's also more consistent with PEP 8, which says:

> However, in a slice the colon acts like a binary operator, and should
have equal amounts on either side (treating it as the operator with the
lowest priority).

Closes #7259.
Closes #8642.

## Test Plan

`cargo test`
@JohannesBuchner
Copy link

I am still getting this unwanted behaviour with ruff-0.9.3:

$ cat > foo.py
lanes[laneid + 1:]
$ ruff format foo.py
1 file reformatted
$ cat foo.py
lanes[laneid + 1 :]

@dhruvmanila
Copy link
Member

@JohannesBuchner That's an expected behavior. What the original issue was pointing out is that E203 rule is removing the whitespace before the : operator while the formatter adds it - causing the conflicting behavior between the linter and the formatter.

@JohannesBuchner
Copy link

@dhruvmanila Thanks for the quick response. flake8 gives the error "E203 whitespace before ':'" with the reformatted output. I see from psf/black#315 that they claim that this is an issue of pep8. There is help at https://ichard26-testblackdocs.readthedocs.io/en/refactor_docs/compatible_configs.html for configuring flake8. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants