This commit is contained in:
peasoft 2026-01-02 23:19:34 +08:00
parent 1c33b7efc7
commit b9d495db40
3 changed files with 10 additions and 8 deletions

View file

@ -25,7 +25,7 @@ def pack(o: t.Any, stream: t.BinaryIO, **kwargs: dict[str, t.Any]):
See :class:`Packer` for options.
"""
packer = Packer(autoreset=True, **kwargs) # type: ignore
packer = Packer(autoreset=True, **kwargs) # type: ignore
stream.write(t.cast(bytes, packer.pack(o)))
@ -35,7 +35,7 @@ def packb(o: t.Any, **kwargs: dict[str, t.Any]):
See :class:`Packer` for options.
"""
return Packer(autoreset=True, **kwargs).pack(o) # type: ignore
return Packer(autoreset=True, **kwargs).pack(o) # type: ignore
def unpack(stream: t.BinaryIO, **kwargs: dict[str, t.Any]):

View file

@ -6,6 +6,7 @@ from collections import namedtuple
class ExtType(namedtuple("ExtType", "code data")):
"""ExtType represents ext type in msgpack."""
code: int
data: bytes
@ -16,7 +17,7 @@ class ExtType(namedtuple("ExtType", "code data")):
raise TypeError("data must be bytes")
if not 0 <= code <= 127:
raise ValueError("code must be 0~127")
return super().__new__(cls, code, data) # type: ignore
return super().__new__(cls, code, data) # type: ignore
class Timestamp:

View file

@ -7,7 +7,7 @@ import typing as t
from collections.abc import Sequence
from datetime import datetime as _DateTime
_ClassInfo: t.TypeAlias = type | types.UnionType | tuple['_ClassInfo', ...]
_ClassInfo: t.TypeAlias = type | types.UnionType | tuple["_ClassInfo", ...]
_Pair = tuple[t.Any, t.Any]
_Pairs = t.Iterable[_Pair]
_SizeFmt = tuple[int, str]
@ -90,7 +90,7 @@ def unpackb(packed: bytes, **kwargs: dict[str, t.Any]):
See :class:`Unpacker` for options.
"""
unpacker = Unpacker(None, max_buffer_size=len(packed), **kwargs) # type: ignore
unpacker = Unpacker(None, max_buffer_size=len(packed), **kwargs) # type: ignore
unpacker.feed(packed)
try:
ret = unpacker._unpack()
@ -528,19 +528,20 @@ class Unpacker:
return
if self._object_pairs_hook is not None:
ret = self._object_pairs_hook(
(self._unpack(EX_CONSTRUCT), self._unpack(EX_CONSTRUCT)) for _ in range(n) # type: ignore
(self._unpack(EX_CONSTRUCT), self._unpack(EX_CONSTRUCT))
for _ in range(n) # type: ignore
)
else:
ret = {}
for _ in range(n):
key = self._unpack(EX_CONSTRUCT)
if self._strict_map_key and type(key) not in (str, bytes):
raise ValueError("%s is not allowed for map key" % str(type(key))) # type: ignore
raise ValueError("%s is not allowed for map key" % str(type(key))) # type: ignore
if isinstance(key, str):
key = sys.intern(key)
ret[key] = self._unpack(EX_CONSTRUCT)
if self._object_hook is not None:
ret = self._object_hook(ret) # type: ignore
ret = self._object_hook(ret) # type: ignore
return ret
if execute == EX_SKIP:
return