Skip to content

Commit 5ed2484

Browse files
authored
Merge pull request #348 from takluyver/i343
Fix inspecting version with a subscript assignment in the code
2 parents a640b3b + 568227a commit 5ed2484

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

flit_core/flit_core/common.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,13 @@ def get_docstring_and_version_via_ast(target):
128128
for child in node.body:
129129
# Only use the version from the given module if it's a simple
130130
# string assignment to __version__
131-
is_version_str = (isinstance(child, ast.Assign) and
132-
len(child.targets) == 1 and
133-
child.targets[0].id == "__version__" and
134-
isinstance(child.value, ast.Str))
131+
is_version_str = (
132+
isinstance(child, ast.Assign)
133+
and len(child.targets) == 1
134+
and isinstance(child.targets[0], ast.Name)
135+
and child.targets[0].id == "__version__"
136+
and isinstance(child.value, ast.Str)
137+
)
135138
if is_version_str:
136139
version = child.value.s
137140
break

flit_core/flit_core/tests/samples/module2.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22
Docstring formatted like this.
33
"""
44

5+
a = {}
6+
# An assignment to a subscript (a['test']) broke introspection
7+
# https://github.com/takluyver/flit/issues/343
8+
a['test'] = 6
9+
510
__version__ = '7.0'

0 commit comments

Comments
 (0)