Skip to content

Commit e38b172

Browse files
authored
Merge pull request #684 from tacaswell/fix/py314
MNT: fix compatibility with Python 3.14
2 parents e6b564b + 6ab62c9 commit e38b172

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

flit_core/flit_core/common.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ def get_docstring_and_version_via_ast(target):
148148
with target_path.open('rb') as f:
149149
node = ast.parse(f.read())
150150
for child in node.body:
151+
if sys.version_info >= (3, 8):
152+
target_type = ast.Constant
153+
else:
154+
target_type = ast.Str
151155
# Only use the version from the given module if it's a simple
152156
# string assignment to __version__
153157
is_version_str = (
@@ -157,10 +161,13 @@ def get_docstring_and_version_via_ast(target):
157161
and target.id == "__version__"
158162
for target in child.targets
159163
)
160-
and isinstance(child.value, ast.Str)
164+
and isinstance(child.value, target_type)
161165
)
162166
if is_version_str:
163-
version = child.value.s
167+
if sys.version_info >= (3, 8):
168+
version = child.value.value
169+
else:
170+
version = child.value.s
164171
break
165172
return ast.get_docstring(node), version
166173

0 commit comments

Comments
 (0)