Skip to content

Commit

Permalink
Backward compatibility wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Hook25 committed Nov 12, 2024
1 parent 63cc852 commit b5c77f5
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions checkbox-ng/plainbox/impl/new_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L222 was not covered by tests

# 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"])

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L227 was not covered by tests

def wrapping(attr):
def _f(parsed_ast):
wrapped_parsed_ast = Wrapper(getattr(parsed_ast, attr))
return ConstantGetter(wrapped_parsed_ast)

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

View check run for this annotation

Codecov / codecov/patch

checkbox-ng/plainbox/impl/new_resource.py#L229-L232

Added lines #L229 - L232 were not covered by tests

legacy_getters = {

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L234 was not covered by tests
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,
}

Expand Down

0 comments on commit b5c77f5

Please sign in to comment.