Skip to content

Commit 14b4f36

Browse files
committed
error on non-constant
1 parent 167003a commit 14b4f36

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

setup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def parse_version(fpath):
4444

4545
def static_parse(varname, fpath):
4646
"""
47-
Statically parse the a constant variable from a python file
47+
Statically parse the a constant variable from a python file.
48+
Raise an error if the variable is not a constant.
4849
"""
4950
import ast
5051

@@ -59,8 +60,9 @@ def visit_Assign(self, node: ast.Assign):
5960
for target in node.targets:
6061
if getattr(target, "id", None) == varname:
6162
value: ast.expr = node.value
62-
if isinstance(value, ast.Constant) and isinstance(value.value, str):
63-
self.static_value = value.value
63+
if not isinstance(value, ast.Constant):
64+
raise ValueError("variable {!r} is not a constant".format(varname))
65+
self.static_value = value.value
6466

6567
visitor = StaticVisitor()
6668
visitor.visit(pt)

0 commit comments

Comments
 (0)