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

Formatter: stub files only have one empty lines between top level items #5821

Closed
konstin opened this issue Jul 17, 2023 · 2 comments · Fixed by #6501
Closed

Formatter: stub files only have one empty lines between top level items #5821

konstin opened this issue Jul 17, 2023 · 2 comments · Fixed by #6501
Labels
formatter Related to the formatter good first issue Good for newcomers help wanted Contributions especially welcome

Comments

@konstin
Copy link
Member

konstin commented Jul 17, 2023

Black only formats one empty line between top level items in stub files (.pyi), while it uses two empty lines in regular python files. When single line classes, method and functions of the same kind that are stubbed out with ellipses follow each they don't get any empty lines.

scratch.py

class A:
    def __init__(self):
        pass


class B:
    def __init__(self):
        pass


def foo():
    pass


class Del(expr_context):
    ...


class Load(expr_context):
    ...


class Store(expr_context):
    ...

scratch.pyi

class A:
    def __init__(self):
        pass

class B:
    def __init__(self):
        pass

def foo():
    pass

class Del(expr_context): ...
class Load(expr_context): ...
class Store(expr_context): ...

The relevant code is below, which doesn't have access to whether it's in a stub file or not yet.

&format_args![empty_line(), empty_line()],

@konstin konstin added the formatter Related to the formatter label Jul 17, 2023
@MichaReiser
Copy link
Member

Note: This requires knowing the file type during formatting by passing it to the format context.

@MichaReiser MichaReiser added this to the Formatter: Stable milestone Jul 31, 2023
@konstin konstin added good first issue Good for newcomers help wanted Contributions especially welcome labels Aug 10, 2023
@konstin
Copy link
Member Author

konstin commented Aug 10, 2023

PyFormatOptions now has a source_type field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter good first issue Good for newcomers help wanted Contributions especially welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants