Skip to content

Commit

Permalink
MNT: fix compatibility with Python 3.14
Browse files Browse the repository at this point in the history
The ast.Str class was deprecated in 3.8 and will be removed in 3.14
  • Loading branch information
tacaswell committed May 28, 2024
1 parent e6b564b commit 6ab62c9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions flit_core/flit_core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ def get_docstring_and_version_via_ast(target):
with target_path.open('rb') as f:
node = ast.parse(f.read())
for child in node.body:
if sys.version_info >= (3, 8):
target_type = ast.Constant
else:
target_type = ast.Str
# Only use the version from the given module if it's a simple
# string assignment to __version__
is_version_str = (
Expand All @@ -157,10 +161,13 @@ def get_docstring_and_version_via_ast(target):
and target.id == "__version__"
for target in child.targets
)
and isinstance(child.value, ast.Str)
and isinstance(child.value, target_type)
)
if is_version_str:
version = child.value.s
if sys.version_info >= (3, 8):
version = child.value.value
else:
version = child.value.s
break
return ast.get_docstring(node), version

Expand Down

0 comments on commit 6ab62c9

Please sign in to comment.