From daed32e462abb5a90d4266a14a07a3759a7a50e7 Mon Sep 17 00:00:00 2001 From: Simon de Vlieger Date: Thu, 12 Jun 2025 15:59:32 +0200 Subject: [PATCH] compat: `ast.Str` -> `ast.Constant` Python 3.14 removed the long deprecated `ast.Str` [1]. Rewrite to use `ast.Constant` conditionally for any version that isn't 3.6. Since 3.6 is our lowest supported version we don't check for below. Signed-off-by: Simon de Vlieger --- osbuild/meta.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/osbuild/meta.py b/osbuild/meta.py index 63971297..0c5f256b 100644 --- a/osbuild/meta.py +++ b/osbuild/meta.py @@ -39,6 +39,8 @@ from .util import osrelease FAILED_TITLE = "JSON Schema validation failed" FAILED_TYPEURI = "https://osbuild.org/validation-error" +IS_PY36 = sys.version_info[:2] == (3, 6) + class ValidationError: """Describes a single failed validation @@ -456,11 +458,21 @@ class ModuleInfo: return {} value = node.value - if not isinstance(value, ast.Str): - return {} + + if IS_PY36: + if not isinstance(value, ast.Str): + return {} + + # Get the internal value + value = value.s + else: + if not isinstance(value, ast.Constant): + return {} + + value = value.value try: - return json.loads("{" + value.s + "}") + return json.loads("{" + value + "}") except json.decoder.JSONDecodeError as e: msg = "Invalid schema: " + e.msg line = e.doc.splitlines()[e.lineno - 1] @@ -474,7 +486,10 @@ class ModuleInfo: if not node: return set() - return {e.s for e in node.value.elts} + if IS_PY36: + return {e.s for e in node.value.elts} + + return {e.value for e in node.value.elts} @classmethod def load(cls, root, klass, name) -> Optional["ModuleInfo"]: