spack style --spec-strings: fix non-str constant issue (#49492)

This commit is contained in:
Harmen Stoppels 2025-03-14 21:54:02 +01:00 committed by GitHub
parent 69b7c32b5d
commit 60be77f761
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -636,7 +636,7 @@ def _spec_str_ast(path: str, tree: ast.AST, handler: SpecStrHandler) -> None:
"""Walk the AST of a Python file and apply handler to formatted spec strings."""
has_constant = sys.version_info >= (3, 8)
for node in ast.walk(tree):
if has_constant and isinstance(node, ast.Constant):
if has_constant and isinstance(node, ast.Constant) and isinstance(node.value, str):
current_str = node.value
elif not has_constant and isinstance(node, ast.Str):
current_str = node.s

View File

@ -415,7 +415,7 @@ def test_spec_strings(tmp_path):
(tmp_path / "example.py").write_text(
"""\
def func(x):
print("dont fix %s me" % x)
print("dont fix %s me" % x, 3)
return x.satisfies("+foo %gcc +bar") and x.satisfies("%gcc +baz")
"""
)
@ -500,7 +500,7 @@ def collect_issues(path: str, line: int, col: int, old: str, new: str):
(tmp_path / "example.py").read_text()
== """\
def func(x):
print("dont fix %s me" % x)
print("dont fix %s me" % x, 3)
return x.satisfies("+foo +bar %gcc") and x.satisfies("+baz %gcc")
"""
)