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

[E301] Failing to catch blank lines above classmethods when compared to pycodestyle #10114

Closed
dfrtz opened this issue Feb 24, 2024 · 2 comments · Fixed by #10117
Closed

[E301] Failing to catch blank lines above classmethods when compared to pycodestyle #10114

dfrtz opened this issue Feb 24, 2024 · 2 comments · Fixed by #10117
Labels
bug Something isn't working help wanted Contributions especially welcome preview Related to preview mode features

Comments

@dfrtz
Copy link

dfrtz commented Feb 24, 2024

The closest I could find to this is #10039, but it appears to be a bit different, as it is talking about conflicts with format on pyi files, but this is impacting regular files and specifically classmethods. I also saw E301 mentioned in #10032 as potentially superfluous with formatter, but I don't see it listed in documentation as having conflicts. Blank line spacing around the E rules is also discussed in some PRs like #8720, but they do not appear to cover this specific scenario. I believe it should still be able to be caught when format is not used for parity with pycodestyle, which does catch these.

pyproject.toml

[tool.ruff.lint]
select = [
  "E",
  "W",
]

Python file

"""Minimal repo."""


class MinRepoClassA:
    """Class for minimal repo."""

    columns = []
    @classmethod
    def cls_method_a(cls) -> None:
        pass
    @classmethod
    def cls_method_b(cls) -> None:
        pass
    def method_a(self) -> None:
        pass
    def method_b(self) -> None:
        pass

pycodestyle 2.11.1 catching all 4

$ pycodestyle --count min_repo.py
min_repo.py:8:5: E301 expected 1 blank line, found 0
min_repo.py:11:5: E301 expected 1 blank line, found 0
min_repo.py:14:5: E301 expected 1 blank line, found 0
min_repo.py:16:5: E301 expected 1 blank line, found 0
4

ruff 0.2.2 catching 2/4

$ ruff --version
ruff 0.2.2
$ ruff check --preview min_repo.py
min_repo.py:14:5: E301 [*] Expected 1 blank line, found 0
   |
12 |     def cls_method_b(cls) -> None:
13 |         pass
14 |     def method_a(self) -> None:
   |     ^^^ E301
15 |         pass
16 |     def method_b(self) -> None:
   |
   = help: Add missing blank line

min_repo.py:16:5: E301 [*] Expected 1 blank line, found 0
   |
14 |     def method_a(self) -> None:
15 |         pass
16 |     def method_b(self) -> None:
   |     ^^^ E301
17 |         pass
   |
   = help: Add missing blank line

Found 2 errors.
[*] 2 fixable with the `--fix` option.

To note, if using ruff format, it would fix all 4. If you are only using ruff as a replacement for pycodestyle without format however, then you would hit this miss without pycodestyle.

$ ruff format --check min_repo.py --diff
--- min_repo.py
+++ min_repo.py
@@ -5,13 +5,17 @@
     """Class for minimal repo."""
 
     columns = []
+
     @classmethod
     def cls_method_a(cls) -> None:
         pass
+
     @classmethod
     def cls_method_b(cls) -> None:
         pass
+
     def method_a(self) -> None:
         pass
+
     def method_b(self) -> None:
         pass

1 file would be reformatted

I see E301 is in preview, but this does not appear to be intentional based on pycodestyle behavior, and it working with regular methods. I also did not see any configuration options to change this behavior, but please let me know if I am overlooking something. Thanks!

@MichaReiser
Copy link
Member

Thanks. Yeah I agree this is a bug. @hoel-bagard, would you be interested in looking into this issue? Just be aware, that there's one open PR that restructures the code. So maybe it would be best to start of that branch. #10098

@MichaReiser MichaReiser added bug Something isn't working help wanted Contributions especially welcome preview Related to preview mode features labels Feb 25, 2024
@hoel-bagard
Copy link
Contributor

@MichaReiser I'll look into fixing this, thanks for the notice!

hoel-bagard added a commit to hoel-bagard/ruff that referenced this issue Feb 25, 2024
hoel-bagard added a commit to hoel-bagard/ruff that referenced this issue Feb 27, 2024
MichaReiser pushed a commit to hoel-bagard/ruff that referenced this issue Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Contributions especially welcome preview Related to preview mode features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants