From 60be77f761f8cb5b5d39deae55c2f386b7a7ce6a Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Fri, 14 Mar 2025 21:54:02 +0100 Subject: [PATCH] spack style --spec-strings: fix non-str constant issue (#49492) --- lib/spack/spack/cmd/style.py | 2 +- lib/spack/spack/test/cmd/style.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/spack/spack/cmd/style.py b/lib/spack/spack/cmd/style.py index 68cbe750746..aff309cc65b 100644 --- a/lib/spack/spack/cmd/style.py +++ b/lib/spack/spack/cmd/style.py @@ -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 diff --git a/lib/spack/spack/test/cmd/style.py b/lib/spack/spack/test/cmd/style.py index a7aaefe7731..91c9561f612 100644 --- a/lib/spack/spack/test/cmd/style.py +++ b/lib/spack/spack/test/cmd/style.py @@ -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") """ )