Skip to content

Commit 3d51013

Browse files
committed
Further compatibility fix for Python 3.12
1 parent 93124a1 commit 3d51013

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

astatine/__init__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
# stdlib
3535
import ast
36+
import sys
3637
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type, Union, cast
3738

3839
# 3rd party
@@ -47,18 +48,22 @@
4748
try: # pragma: no cover
4849
# 3rd party
4950
import typed_ast.ast3
50-
Str = (ast.Str, typed_ast.ast3.Str)
5151
Constant = (
5252
ast.Constant,
5353
typed_ast.ast3.Constant, # type: ignore[attr-defined]
5454
)
5555
Expr = (ast.Expr, typed_ast.ast3.Expr)
5656

57+
if sys.version_info < (3, 12):
58+
Str = (ast.Str, typed_ast.ast3.Str)
59+
5760
except ImportError: # pragma: no cover
58-
Str = (ast.Str, )
5961
Constant = (ast.Constant, )
6062
Expr = (ast.Expr, )
6163

64+
if sys.version_info < (3, 12):
65+
Str = (ast.Str, )
66+
6267
__author__: str = "Dominic Davis-Foster"
6368
__copyright__: str = "2021 Dominic Davis-Foster"
6469
__license__: str = "MIT License"
@@ -166,10 +171,12 @@ def get_docstring_lineno(node: Union[ast.FunctionDef, ast.ClassDef, ast.Module])
166171

167172
if isinstance(body, Constant) and isinstance(body.value, str): # pragma: no cover (<py38)
168173
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
173180

174181

175182
def kwargs_from_node(

0 commit comments

Comments
 (0)