From 88b9a4b6f7a2cc7123a0249669948aa053fa2535 Mon Sep 17 00:00:00 2001 From: Hook25 Date: Tue, 12 Nov 2024 09:39:22 +0100 Subject: [PATCH] Backward compatibility wrapper --- checkbox-ng/plainbox/impl/new_resource.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/checkbox-ng/plainbox/impl/new_resource.py b/checkbox-ng/plainbox/impl/new_resource.py index f0c851a82..c64997746 100644 --- a/checkbox-ng/plainbox/impl/new_resource.py +++ b/checkbox-ng/plainbox/impl/new_resource.py @@ -219,11 +219,25 @@ def __str__(self): legacy_getters = {} if sys.version_info[0] == 3 and sys.version_info[1] < 8: - # older version of python have + from collections import namedtuple + + # older version of python have slightly different nodes to parse + # constants. Here we wrap them for forward compatibility putting the old + # attribute where the ConstantGetter expects to find it + Wrapper = namedtuple("Wrapper", ["value"]) + + def wrapping(attr): + def _f(parsed_ast): + wrapped_parsed_ast = Wrapper(getattr(parsed_ast, attr)) + return ConstantGetter(wrapped_parsed_ast) + + return _f + legacy_getters = { - ast.Str: ConstantGetter, - ast.Num: ConstantGetter, - ast.Bytes: ConstantGetter, + ast.Str: wrapping("s"), + ast.Num: wrapping("n"), + ast.Bytes: wrapping("s"), + # this actually uses .value ast.NameConstant: ConstantGetter, }