Skip to content

Formatter: Empty lines in stub files #6723

@konstin

Description

@konstin

When formatting typeshed (cargo run --bin ruff_dev -- format-dev --write typeshed), there is still a big diff with black wrt to empty lines.

E.g. given

class Feature:
    def getMandatoryRelease(self) -> None: ...
    compiler_flag: int

def getMandatoryRelease(self) -> None: ...
compiler_flag: int

if sys.platform != "win32":
    def can_change_color() -> bool: ...
    # Changed in Python 3.8.8 and 3.9.2
    if sys.version_info >= (3, 8):
        pass

if sys.platform == "win32":
    class Dummy:
        __new__: None
        __init__: None

    # Actual typename SummaryInformation, not exposed by the implementation
    class _SummaryInformation:
        def GetProperty(self, field: int) -> int | bytes | None: ...

black will format this as

class Feature:
    def getMandatoryRelease(self) -> None: ...
    compiler_flag: int

def getMandatoryRelease(self) -> None: ...

compiler_flag: int

if sys.platform != "win32":
    def can_change_color() -> bool: ...
    # Changed in Python 3.8.8 and 3.9.2
    if sys.version_info >= (3, 8):
        pass

if sys.platform == "win32":
    class Dummy:
        __new__: None
        __init__: None

    # Actual typename SummaryInformation, not exposed by the implementation
    class _SummaryInformation:
        def GetProperty(self, field: int) -> int | bytes | None: ...

while we format this as

class Feature:
    def getMandatoryRelease(self) -> None: ...

    compiler_flag: int

def getMandatoryRelease(self) -> None: ...

compiler_flag: int

if sys.platform != "win32":

    def can_change_color() -> bool: ...

    # Changed in Python 3.8.8 and 3.9.2
    if sys.version_info >= (3, 8):
        pass

if sys.platform == "win32":

    class Dummy:
        __new__: None
        __init__: None

    # Actual typename SummaryInformation, not exposed by the implementation
    class _SummaryInformation:
        def GetProperty(self, field: int) -> int | bytes | None: ...

The task is to go through the typeshed diff and figure out each empty line rule we're still missing. If you implement this you don't need to (and probably shouldn't) fix everything at once but you can implement any part of it (as long as it doesn't decrease the similarity index).

Metadata

Metadata

Assignees

Labels

formatterRelated to the formatterhelp wantedContributions especially welcome

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions