File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -471,3 +471,18 @@ def is_string_variable(
471471 return True
472472
473473 return False
474+
475+
476+ def is_docstring_at_end_of_file (tokens : list [tokenize .TokenInfo ], index : int ) -> bool :
477+ """Determine if the docstring is at the end of the file."""
478+ for i in range (index + 1 , len (tokens )):
479+ tok = tokens [i ]
480+ if tok .type not in (
481+ tokenize .NL ,
482+ tokenize .NEWLINE ,
483+ tokenize .DEDENT ,
484+ tokenize .ENDMARKER ,
485+ ):
486+ return False
487+
488+ return True
Original file line number Diff line number Diff line change @@ -379,7 +379,10 @@ def _get_newlines_by_type(
379379 int
380380 The number of newlines to insert after the docstring.
381381 """
382- if _classify .is_module_docstring (tokens , index ):
382+ if _classify .is_docstring_at_end_of_file (tokens , index ):
383+ # print("End of file")
384+ return 0
385+ elif _classify .is_module_docstring (tokens , index ):
383386 # print("Module")
384387 return _get_module_docstring_newlines (black )
385388 elif _classify .is_class_docstring (tokens , index ):
You can’t perform that action at this time.
0 commit comments