Skip to content

Commit

Permalink
Merge pull request #348 from takluyver/i343
Browse files Browse the repository at this point in the history
Fix inspecting version with a subscript assignment in the code
  • Loading branch information
takluyver committed Jun 15, 2020
2 parents a640b3b + 568227a commit 5ed2484
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 7 additions & 4 deletions flit_core/flit_core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,13 @@ def get_docstring_and_version_via_ast(target):
for child in node.body:
# Only use the version from the given module if it's a simple
# string assignment to __version__
is_version_str = (isinstance(child, ast.Assign) and
len(child.targets) == 1 and
child.targets[0].id == "__version__" and
isinstance(child.value, ast.Str))
is_version_str = (
isinstance(child, ast.Assign)
and len(child.targets) == 1
and isinstance(child.targets[0], ast.Name)
and child.targets[0].id == "__version__"
and isinstance(child.value, ast.Str)
)
if is_version_str:
version = child.value.s
break
Expand Down
5 changes: 5 additions & 0 deletions flit_core/flit_core/tests/samples/module2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
Docstring formatted like this.
"""

a = {}
# An assignment to a subscript (a['test']) broke introspection
# https://github.com/takluyver/flit/issues/343
a['test'] = 6

__version__ = '7.0'

0 comments on commit 5ed2484

Please sign in to comment.