From 63cc852a86c07a439460ffc9ef879aeb59ab11b1 Mon Sep 17 00:00:00 2001 From: Hook25 Date: Mon, 11 Nov 2024 18:05:33 +0100 Subject: [PATCH] Support legacy Constant ast nodes Old python makes me sad --- checkbox-ng/plainbox/impl/new_resource.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/checkbox-ng/plainbox/impl/new_resource.py b/checkbox-ng/plainbox/impl/new_resource.py index 7ccf68896..f0c851a82 100644 --- a/checkbox-ng/plainbox/impl/new_resource.py +++ b/checkbox-ng/plainbox/impl/new_resource.py @@ -1,3 +1,4 @@ +import sys import ast import typing import textwrap @@ -216,6 +217,17 @@ def __str__(self): return "[{}]".format(to_r) +legacy_getters = {} +if sys.version_info[0] == 3 and sys.version_info[1] < 8: + # older version of python have + legacy_getters = { + ast.Str: ConstantGetter, + ast.Num: ConstantGetter, + ast.Bytes: ConstantGetter, + ast.NameConstant: ConstantGetter, + } + + def getter_from_ast(parsed_ast): """ Rappresents a way to fetch a value @@ -229,6 +241,7 @@ def getter_from_ast(parsed_ast): ast.UnaryOp: ConstantGetter.from_unary_op, # such as: not True ast.Name: NamedConstant, # such as: DESKTOP_PC_PRODUCT } + getters.update(legacy_getters) try: getter = getters[type(parsed_ast)] except KeyError: