Implement blank_line_after_nested_stub_class preview style (#9155)

## 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
This commit is contained in:
Dhruv Manilawala 2024-01-31 00:09:38 +05:30 committed by GitHub
parent 79f0522eb7
commit 541aef4e6c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 891 additions and 29 deletions

View file

@ -0,0 +1,6 @@
[
{
"source_type": "Stub",
"preview": "enabled"
}
]

View file

@ -0,0 +1,183 @@
class Top1:
pass
class Top2:
pass
class Top:
class Ellipsis: ...
class Ellipsis: ...
class Top:
class Ellipsis: ...
class Pass:
pass
class Top:
class Ellipsis: ...
class_variable = 1
class Top:
class TrailingComment:
pass
# comment
class Other:
pass
class Top:
class CommentWithEllipsis: ...
# comment
class Other: ...
class Top:
class TrailingCommentWithMultipleBlankLines:
pass
# comment
class Other:
pass
class Top:
class Nested:
pass
# comment
class LeadingComment:
pass
class Top:
@decorator
class Ellipsis: ...
class Ellipsis: ...
class Top:
@decorator
class Ellipsis: ...
@decorator
class Ellipsis: ...
class Top:
@decorator
class Ellipsis: ...
@decorator
class Pass:
pass
class Top:
class Foo:
pass
class AfterMultipleEmptyLines:
pass
class Top:
class Nested11:
class Nested12:
pass
class Nested21:
pass
class Top:
class Nested11:
class Nested12:
pass
# comment
class Nested21:
pass
class Top:
class Nested11:
class Nested12:
pass
# comment
class Nested21:
pass
# comment
class Top1:
class Nested:
pass
class Top2:
pass
class Top1:
class Nested:
pass
# comment
class Top2:
pass
class Top1:
class Nested:
pass
# comment
class Top2:
pass
if foo:
class Nested1:
pass
class Nested2:
pass
else:
pass
if foo:
class Nested1:
pass
class Nested2:
pass
# comment
elif bar:
class Nested1:
pass
# comment
else:
pass
if top1:
class Nested:
pass
if top2:
pass
if top1:
class Nested:
pass
# comment
if top2:
pass
if top1:
class Nested:
pass
# comment
if top2:
pass
try:
class Try:
pass
except:
class Except:
pass
foo = 1
match foo:
case 1:
class Nested:
pass
case 2:
class Nested:
pass
case _:
class Nested:
pass
foo = 1
class Eof:
class Nested:
pass

View file

@ -0,0 +1,6 @@
[
{
"source_type": "Stub",
"preview": "enabled"
}
]

View file

@ -0,0 +1,17 @@
# A separate file to test out the behavior when there are a mix of blank lines
# and comments at EOF just after a nested stub class.
class Top:
class Nested1:
class Nested12:
pass
# comment
class Nested2:
pass
# comment