From e99dd5d752e7413a8f58919b620afa4026703fde Mon Sep 17 00:00:00 2001 From: Tim Rid <6593626+timrid@users.noreply.github.com> Date: Sun, 13 Feb 2022 19:30:35 +0100 Subject: [PATCH] some renaming --- construct_typed/tenum.py | 20 ++++++++++---------- tests/test_typed.py | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/construct_typed/tenum.py b/construct_typed/tenum.py index 47b089c..b146549 100644 --- a/construct_typed/tenum.py +++ b/construct_typed/tenum.py @@ -162,15 +162,15 @@ class TFlags(enum.IntFlag, metaclass=_EnumMeta): @classmethod def __construct__( - cls: "t.Type[FlagsEnumType]", - ) -> "TFlagsConstruct[FlagsEnumType]": + cls: "t.Type[FlagsType]", + ) -> "TFlagsConstruct[FlagsType]": ... -FlagsEnumType = t.TypeVar("FlagsEnumType", bound=TFlags) +FlagsType = t.TypeVar("FlagsType", bound=TFlags) -class TFlagsConstruct(Adapter[int, int, FlagsEnumType, FlagsEnumType]): +class TFlagsConstruct(Adapter[int, int, FlagsType, FlagsType]): """ Typed flags. """ @@ -178,28 +178,28 @@ class TFlagsConstruct(Adapter[int, int, FlagsEnumType, FlagsEnumType]): if t.TYPE_CHECKING: def __new__( - cls, subcon: Construct[int, int], enum_type: t.Type[FlagsEnumType] - ) -> "TFlagsConstruct[FlagsEnumType]": + cls, subcon: Construct[int, int], enum_type: t.Type[FlagsType] + ) -> "TFlagsConstruct[FlagsType]": ... - def __init__(self, subcon: Construct[int, int], enum_type: t.Type[FlagsEnumType]): + def __init__(self, subcon: Construct[int, int], enum_type: t.Type[FlagsType]): if not issubclass(enum_type, TFlags): raise TypeError( "'{}' has to be a '{}'".format(repr(enum_type), repr(TFlags)) ) # save enum type - self.enum_type = t.cast(t.Type[FlagsEnumType], enum_type) # type: ignore + self.enum_type = t.cast(t.Type[FlagsType], enum_type) # type: ignore # init adatper super(TFlagsConstruct, self).__init__(subcon) # type: ignore - def _decode(self, obj: int, context: Context, path: PathType) -> FlagsEnumType: + def _decode(self, obj: int, context: Context, path: PathType) -> FlagsType: return self.enum_type(obj) def _encode( self, - obj: FlagsEnumType, + obj: FlagsType, context: Context, path: PathType, ) -> int: diff --git a/tests/test_typed.py b/tests/test_typed.py index b69e50c..8efdbb5 100644 --- a/tests/test_typed.py +++ b/tests/test_typed.py @@ -359,19 +359,19 @@ def test_tenum_in_dataclass_struct() -> None: ) -def test_tenum_flags() -> None: - class TestEnum(TFlags, subcon=cs.Byte): +def test_tflags() -> None: + class TestFlags(TFlags, subcon=cs.Byte): one = 1 two = 2 four = 4 eight = 8 - d = construct(TestEnum) - common(d, b"\x03", TestEnum.one | TestEnum.two, 1) - assert d.build(TestEnum(0)) == b"\x00" - assert d.build(TestEnum.one | TestEnum.two) == b"\x03" - assert d.build(TestEnum(8)) == b"\x08" - assert d.build(TestEnum(1 | 2)) == b"\x03" - assert d.build(TestEnum(255)) == b"\xff" - assert d.build(TestEnum.eight) == b"\x08" + d = construct(TestFlags) + common(d, b"\x03", TestFlags.one | TestFlags.two, 1) + assert d.build(TestFlags(0)) == b"\x00" + assert d.build(TestFlags.one | TestFlags.two) == b"\x03" + assert d.build(TestFlags(8)) == b"\x08" + assert d.build(TestFlags(1 | 2)) == b"\x03" + assert d.build(TestFlags(255)) == b"\xff" + assert d.build(TestFlags.eight) == b"\x08" assert raises(d.build, 2) == TypeError