Skip to content

Commit 61afe6e

Browse files
authored
Merge pull request #317 from MarcinKonowalczyk/fix-setup-in-3.14
Updated StaticVisitor
2 parents 6917359 + 14b4f36 commit 61afe6e

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

setup.py

Lines changed: 7 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

@@ -55,10 +56,13 @@ def static_parse(varname, fpath):
5556
pt = ast.parse(sourcecode)
5657

5758
class StaticVisitor(ast.NodeVisitor):
58-
def visit_Assign(self, node):
59+
def visit_Assign(self, node: ast.Assign):
5960
for target in node.targets:
6061
if getattr(target, "id", None) == varname:
61-
self.static_value = node.value.s
62+
value: ast.expr = node.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
6266

6367
visitor = StaticVisitor()
6468
visitor.visit(pt)

0 commit comments

Comments
 (0)