mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-10 18:59:33 +00:00
Use modern typehint syntax
This commit is contained in:
@@ -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
|
||||
|
@@ -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")
|
||||
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user