File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,7 +44,8 @@ def parse_version(fpath):
4444
4545def 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 )
You can’t perform that action at this time.
0 commit comments