File tree Expand file tree Collapse file tree 4 files changed +45
-1
lines changed
Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -463,7 +463,7 @@ def is_string_variable(
463463 try :
464464 _token_types = (tokenize .AWAIT , tokenize .OP )
465465 except AttributeError :
466- _token_types = (tokenize .OP ,) # type: ignore
466+ _token_types = (tokenize .OP ,)
467467
468468 if prev_token .type in _token_types and (
469469 '= """' in token .line or token .line in prev_token .line
Original file line number Diff line number Diff line change @@ -260,11 +260,22 @@ def _get_class_docstring_newlines(
260260 The number of newlines to insert after the docstring.
261261 """
262262 j = index + 1
263+ indention_level = tokens [index ].start [1 ]
263264
264265 # The docstring is followed by a comment.
265266 if tokens [j ].string .startswith ("#" ):
266267 return 0
267268
269+ while j < len (tokens ):
270+ if tokens [j ].type in (tokenize .NL , tokenize .NEWLINE ):
271+ j += 1
272+ continue
273+
274+ if tokens [j ].start [1 ] < indention_level :
275+ return 2
276+
277+ break
278+
268279 return 1
269280
270281
Original file line number Diff line number Diff line change @@ -1160,3 +1160,34 @@ expected='''def foo(bar):
11601160 Description.
11611161 """
11621162'''
1163+
1164+ [two_lines_between_stub_classes ]
1165+ source =''' class Foo:
1166+ """Foo class."""
1167+ class Bar:
1168+ """Bar class."""
1169+ '''
1170+ expected =''' class Foo:
1171+ """Foo class."""
1172+
1173+
1174+ class Bar:
1175+ """Bar class."""
1176+ '''
1177+
1178+ [two_lines_between_stub_classes_with_preceding_comment ]
1179+ source =''' class Foo:
1180+ """Foo class."""
1181+
1182+ # A comment for class Bar
1183+ class Bar:
1184+ """Bar class."""
1185+ '''
1186+ expected =''' class Foo:
1187+ """Foo class."""
1188+
1189+
1190+ # A comment for class Bar
1191+ class Bar:
1192+ """Bar class."""
1193+ '''
Original file line number Diff line number Diff line change 135135 ("issue_187" , NO_ARGS ),
136136 ("issue_203" , NO_ARGS ),
137137 ("issue_243" , NO_ARGS ),
138+ ("two_lines_between_stub_classes" , NO_ARGS ),
139+ ("two_lines_between_stub_classes_with_preceding_comment" , NO_ARGS ),
138140 ],
139141)
140142def test_do_format_code (test_key , test_args , args ):
You can’t perform that action at this time.
0 commit comments