Use modern typehint syntax

This commit is contained in:
Lonami Exo
2024-03-17 13:06:03 +01:00
parent 9afe2f853d
commit 8267f5d590
72 changed files with 461 additions and 520 deletions

View File

@@ -1,6 +1,7 @@
import functools
import struct
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Type, TypeVar
from collections.abc import Callable
from typing import TYPE_CHECKING, Any, Optional, Type, TypeVar
if TYPE_CHECKING:
from .serializable import Serializable
@@ -96,8 +97,8 @@ def single_deserializer(cls: Type[T]) -> Callable[[bytes], T]:
@functools.cache
def list_deserializer(cls: Type[T]) -> Callable[[bytes], List[T]]:
def deserializer(body: bytes) -> List[T]:
def list_deserializer(cls: Type[T]) -> Callable[[bytes], list[T]]:
def deserializer(body: bytes) -> list[T]:
reader = Reader(body)
vec_id, length = reader.read_fmt("<ii", 8)
assert vec_id == 0x1CB5C415 and length >= 0
@@ -106,14 +107,14 @@ def list_deserializer(cls: Type[T]) -> Callable[[bytes], List[T]]:
return deserializer
def deserialize_i64_list(body: bytes) -> List[int]:
def deserialize_i64_list(body: bytes) -> list[int]:
reader = Reader(body)
vec_id, length = reader.read_fmt("<ii", 8)
assert vec_id == 0x1CB5C415 and length >= 0
return [*reader.read_fmt(f"<{length}q", length * 8)]
def deserialize_i32_list(body: bytes) -> List[int]:
def deserialize_i32_list(body: bytes) -> list[int]:
reader = Reader(body)
vec_id, length = reader.read_fmt("<ii", 8)
assert vec_id == 0x1CB5C415 and length >= 0

View File

@@ -1,5 +1,6 @@
import struct
from typing import Any, Callable, Generic, Optional, TypeVar
from collections.abc import Callable
from typing import Any, Generic, Optional, TypeVar
Return = TypeVar("Return")

View File

@@ -1,12 +1,12 @@
import abc
import struct
from typing import Protocol, Self, Tuple
from typing import Protocol, Self
from .reader import Reader
class HasSlots(Protocol):
__slots__: Tuple[str, ...]
__slots__: tuple[str, ...]
def obj_repr(self: HasSlots) -> str:
@@ -16,7 +16,7 @@ def obj_repr(self: HasSlots) -> str:
class Serializable(abc.ABC):
__slots__: Tuple[str, ...] = ()
__slots__: tuple[str, ...] = ()
@classmethod
@abc.abstractmethod