From b5c77f5547d2b578b063d174de862952a70f6b86 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 | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/checkbox-ng/plainbox/impl/new_resource.py b/checkbox-ng/plainbox/impl/new_resource.py index f0c851a82..f0c2b2edb 100644 --- a/checkbox-ng/plainbox/impl/new_resource.py +++ b/checkbox-ng/plainbox/impl/new_resource.py @@ -219,11 +219,23 @@ 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) + 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, }