Skip to content

Commit

Permalink
Support legacy Constant ast nodes
Browse files Browse the repository at this point in the history
Old python makes me sad
  • Loading branch information
Hook25 committed Nov 11, 2024
1 parent cc67414 commit 63cc852
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions checkbox-ng/plainbox/impl/new_resource.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import ast
import typing
import textwrap
Expand Down Expand Up @@ -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 = {

Check warning on line 223 in checkbox-ng/plainbox/impl/new_resource.py

View check run for this annotation

Codecov / codecov/patch

checkbox-ng/plainbox/impl/new_resource.py#L223

Added line #L223 was not covered by tests
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
Expand All @@ -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:
Expand Down

0 comments on commit 63cc852

Please sign in to comment.