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

Fix E301 not triggering on decorated methods. #10117

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pycodestyle/E30.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,29 @@ def fn2():
# end


# E301
class Class:
"""Class for minimal repo."""

columns = []
@classmethod
def cls_method(cls) -> None:
pass
# end


# E301
class Class:
"""Class for minimal repo."""

def method(cls) -> None:
pass
@classmethod
def cls_method(cls) -> None:
pass
# end


# E302
"""Main module."""
def fn():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,9 @@ impl BlankLinesChecker {
if self.is_not_first_logical_line {
if line.preceding_blank_lines == 0
// Only applies to methods.
&& matches!(line.kind, LogicalLineKind::Function)
&& matches!(line.kind, LogicalLineKind::Function | LogicalLineKind::Decorator)
// Allow groups of one-liners.
&& !(matches!(self.follows, Follows::Def) && !matches!(line.last_token, TokenKind::Colon))
&& matches!(self.class_status, Status::Inside(_))
// The class/parent method's docstring can directly precede the def.
// Allow following a decorator (if there is an error it will be triggered on the first decorator).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,43 @@ E30.py:464:5: E301 [*] Expected 1 blank line, found 0
464 465 | def fn2():
465 466 | pass

E30.py:474:5: E301 [*] Expected 1 blank line, found 0
|
473 | columns = []
474 | @classmethod
| ^ E301
475 | def cls_method(cls) -> None:
476 | pass
|
= help: Add missing blank line

ℹ Safe fix
471 471 | """Class for minimal repo."""
472 472 |
473 473 | columns = []
474 |+
474 475 | @classmethod
475 476 | def cls_method(cls) -> None:
476 477 | pass

E30.py:486:5: E301 [*] Expected 1 blank line, found 0
|
484 | def method(cls) -> None:
485 | pass
486 | @classmethod
| ^ E301
487 | def cls_method(cls) -> None:
488 | pass
|
= help: Add missing blank line

ℹ Safe fix
483 483 |
484 484 | def method(cls) -> None:
485 485 | pass
486 |+
486 487 | @classmethod
487 488 | def cls_method(cls) -> None:
488 489 | pass


Loading
Loading