PyCQA / pycodestyle

Simple Python style checker in one Python file

Home Page:https://pycodestyle.pycqa.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

E302 with @overload: Should the `def`s be grouped together?

stdedos opened this issue · comments

Currently, pycodestyle suggests

@overload
def process(response: None) -> None: ...
@overload
def process(response: int) -> tuple[int, str]: ...
@overload
def process(response: bytes) -> str: ...


def process(response):
    ...  # actual implementation goes here

Should it suggest

@overload
def process(response: None) -> None: ...
@overload
def process(response: int) -> tuple[int, str]: ...
@overload
def process(response: bytes) -> str: ...
def process(response):
    ...  # actual implementation goes here

instead?

From https://peps.python.org/pep-0008/#blank-lines

Extra blank lines may be used (sparingly) to separate groups of related functions. Blank lines may be omitted between a bunch of related one-liners (e.g. a set of dummy implementations).

Since the one-liner @overloads are only there for the types, maybe it doesn't make sense separating them into a new section.

black --preview accepts both styles (but fixes deviations with 2 lines)

black, 22.6.0 (compiled: yes)
Python (CPython) 3.9.18

I don't think it should