PyCQA / pycodestyle

Simple Python style checker in one Python file
https://pycodestyle.pycqa.org
Other
5.03k stars 754 forks source link

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

Closed stdedos closed 1 year ago

stdedos commented 1 year ago

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
asottile commented 1 year ago

I don't think it should