Skip to content

Commit

Permalink
Merge pull request #684 from tacaswell/fix/py314
Browse files Browse the repository at this point in the history
MNT: fix compatibility with Python 3.14
  • Loading branch information
takluyver authored May 29, 2024
2 parents e6b564b + 6ab62c9 commit e38b172
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 e38b172

Please sign in to comment.