|
33 | 33 |
|
34 | 34 | # stdlib
|
35 | 35 | import ast
|
| 36 | +import sys |
36 | 37 | from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type, Union, cast
|
37 | 38 |
|
38 | 39 | # 3rd party
|
|
47 | 48 | try: # pragma: no cover
|
48 | 49 | # 3rd party
|
49 | 50 | import typed_ast.ast3
|
50 |
| - Str = (ast.Str, typed_ast.ast3.Str) |
51 | 51 | Constant = (
|
52 | 52 | ast.Constant,
|
53 | 53 | typed_ast.ast3.Constant, # type: ignore[attr-defined]
|
54 | 54 | )
|
55 | 55 | Expr = (ast.Expr, typed_ast.ast3.Expr)
|
56 | 56 |
|
| 57 | + if sys.version_info < (3, 12): |
| 58 | + Str = (ast.Str, typed_ast.ast3.Str) |
| 59 | + |
57 | 60 | except ImportError: # pragma: no cover
|
58 |
| - Str = (ast.Str, ) |
59 | 61 | Constant = (ast.Constant, )
|
60 | 62 | Expr = (ast.Expr, )
|
61 | 63 |
|
| 64 | + if sys.version_info < (3, 12): |
| 65 | + Str = (ast.Str, ) |
| 66 | + |
62 | 67 | __author__: str = "Dominic Davis-Foster"
|
63 | 68 | __copyright__: str = "2021 Dominic Davis-Foster"
|
64 | 69 | __license__: str = "MIT License"
|
@@ -166,10 +171,12 @@ def get_docstring_lineno(node: Union[ast.FunctionDef, ast.ClassDef, ast.Module])
|
166 | 171 |
|
167 | 172 | if isinstance(body, Constant) and isinstance(body.value, str): # pragma: no cover (<py38)
|
168 | 173 | return body.lineno
|
169 |
| - elif isinstance(body, Str): # pragma: no cover (py38+) |
170 |
| - return body.lineno |
171 |
| - else: # pragma: no cover |
172 |
| - return None |
| 174 | + else: # pragma: no cover (py38+) |
| 175 | + if sys.version_info < (3, 12): # pragma: no cover (py312+) |
| 176 | + if isinstance(body, Str): |
| 177 | + return body.lineno |
| 178 | + |
| 179 | + return None # pragma: no cover |
173 | 180 |
|
174 | 181 |
|
175 | 182 | def kwargs_from_node(
|
|
0 commit comments