Skip to content

Commit d72d94d

Browse files
set typehint to type instead of Self for metaclass
1 parent 6a79b73 commit d72d94d

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

packer/pack_types/float_types.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
__all__ = ("Float",)
22

33
import struct
4-
from typing import Self
54

65

76
class FloatMeta(type):
8-
def __getitem__(cls, size: int) -> Self:
7+
def __getitem__(cls, size: int) -> type:
98
size_str = "f" if size == 4 else "d"
109
return type(f"{size_str}{cls.__name__}", (cls,), {"_size": size, "_size_str": size_str})
1110

packer/pack_types/int_types.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
"UInt",
44
)
55

6-
from typing import (
7-
Literal,
8-
Self,
9-
)
6+
from typing import Literal
107

118
type INTS = Literal["L1", "L2", "L4", "L8", "B1", "B2", "B4", "B8"]
129

1310

1411
class IntMeta(type):
15-
def __getitem__(cls, size_and_order: INTS) -> Self:
16-
order = "little" if size_and_order[0].lower() == "l" else "big"
12+
def __getitem__(cls, size_and_order: INTS) -> type:
13+
order: Literal["little", "big"] = "little" if size_and_order[0].lower() == "l" else "big"
1714
size = int(size_and_order[1:])
1815

1916
return type(
@@ -24,7 +21,7 @@ def __getitem__(cls, size_and_order: INTS) -> Self:
2421
# TypeDescriptor
2522
class _Int(metaclass=IntMeta):
2623
_size: int = 4
27-
_order: str = "little"
24+
_order: Literal["little", "big"] = "little"
2825
_signed: bool = False
2926

3027
@classmethod

packer/pack_types/size_defined_types.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
__all__ = ("Sized",)
22

3-
from typing import Self
4-
53

64
class SizedMeta(type):
7-
def __getitem__(cls, size: int) -> Self:
5+
def __getitem__(cls, size: int) -> type:
86
return type(f"SIZE{size}{cls.__name__}", (cls,), {"_size": size})
97

108

@@ -21,4 +19,4 @@ def unpack(cls, data: bytes) -> bytes:
2119
return data[: cls._size]
2220

2321

24-
class Sized(bytes, _Sized): ...
22+
class Sized(bytes, _Sized): ... # type: ignore

0 commit comments

Comments
 (0)