Skip to content

Harmonize E301 check with format in --preview mode? #10211

@jab

Description

@jab

ruff format allows overloaded method stubs to occur before the runtime definition with no blank line in between, which is good. But this style fails the E301 check (in preview mode only). Should these be harmonized?

minimal code snippet that reproduces the bug

import typing as t


class Foo:
    """Demo."""

    @t.overload
    def bar(self, x: int) -> int: ...
    @t.overload
    def bar(self, x: str) -> str: ...
    def bar(self, x: int | str) -> int | str:
        return x

commands invoked

❯ ruff format --preview foo.py  # (this example works the same without --preview here too)
1 file left unchanged

❯ ruff check --preview --extend-select E foo.py  # (--preview required here to reproduce)
foo.py:11:5: E301 [*] Expected 1 blank line, found 0
   |
 9 |     @t.overload
10 |     def bar(self, x: str) -> str: ...
11 |     def bar(self, x: int | str) -> int | str:
   |     ^^^ E301
12 |         return x
   |
   = help: Add missing blank line

Found 1 error.
[*] 1 fixable with the `--fix` option.

ruff version

❯ ruff --version
ruff 0.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingincompatibilityIncompatibility between different Ruff tools or rules (formatter, isort, linter)previewRelated to preview mode features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions