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: blank_line_after_nested_stub_class preview style #8891

Closed
Tracked by #8678
MichaReiser opened this issue Nov 29, 2023 · 0 comments · Fixed by #9155
Closed
Tracked by #8678

Formatter: blank_line_after_nested_stub_class preview style #8891

MichaReiser opened this issue Nov 29, 2023 · 0 comments · Fixed by #9155
Assignees
Labels
formatter Related to the formatter help wanted Contributions especially welcome preview Related to preview mode features

Comments

@MichaReiser
Copy link
Member

MichaReiser commented Nov 29, 2023

Implement Black's blank_line_after_nested_stub_class as a preview style. This new style only applies to stub files (.pyi)

class Outer:
    class InnerStub: ...
    outer_attr_after_inner_stub: int
    class Inner:
        inner_attr: int
    outer_attr: int

# output
class Outer:
    class InnerStub: ...
    outer_attr_after_inner_stub: int

    class Inner:
        inner_attr: int

    outer_attr: int

See added new lines after the nested classes (that don't have a dummy body)

@MichaReiser MichaReiser changed the title blank_line_after_nested_stub_class: only applies to stub files (.pyi) Formatter: blank_line_after_nested_stub_class preview style Nov 29, 2023
@MichaReiser MichaReiser added formatter Related to the formatter preview Related to preview mode features help wanted Contributions especially welcome labels Nov 29, 2023
@MichaReiser MichaReiser added this to the Formatter: Stable milestone Nov 29, 2023
@dhruvmanila dhruvmanila self-assigned this Dec 15, 2023
dhruvmanila added a commit that referenced this issue Jan 30, 2024
## Summary

This PR implements the `blank_line_after_nested_stub_class` preview
style in the formatter.

The logic is divided into 3 parts:
1. In between preceding and following nodes at top level and nested
suite
2. When there's a trailing comment after the class
3. When there is no following node from (1) which is the case when it's
the last or the only node in a suite

We handle (3) with `FormatLeadingAlternateBranchComments`.

## Test Plan

- Add new test cases and update existing snapshots
- Checked the `typeshed` diff

fixes: #8891
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter help wanted Contributions especially welcome preview Related to preview mode features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants