File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3737import ast
3838import re
3939from textwrap import dedent , indent
40- from typing import Optional
40+ from typing import Optional , Union
4141
4242__all__ = ["get_docstring_lineno" , "tidy_docstring" ]
4343
4444
45- def get_docstring_lineno (node : ast .AST ) -> Optional [int ]:
45+ def get_docstring_lineno (node : Union [ ast .FunctionDef , ast . ClassDef , ast . Module ] ) -> Optional [int ]:
4646 """
4747 Returns the linenumber of the start of the docstring for ``node``.
4848
@@ -52,12 +52,12 @@ def get_docstring_lineno(node: ast.AST) -> Optional[int]:
5252 if not (node .body and isinstance (node .body [0 ], ast .Expr )):
5353 return None
5454
55- node = node .body [0 ].value
55+ body = node .body [0 ].value
5656
57- if isinstance (node , ast .Str ):
58- return node .lineno
59- elif isinstance (node , ast .Constant ) and isinstance (node .value , str ):
60- return node .lineno # pragma: no cover
57+ if isinstance (body , ast .Str ):
58+ return body .lineno
59+ elif isinstance (body , ast .Constant ) and isinstance (body .value , str ):
60+ return body .lineno # pragma: no cover
6161 else :
6262 return None
6363
You can’t perform that action at this time.
0 commit comments