Код: Выделить всё
import json
from typing_extensions import Any
import lz4.block
bytebuf = bytes | bytearray
MAGIC_HEADER = b"mozLz40\0"
def jsonlz4_loads(buf: str | bytebuf) -> Any:
if isinstance(buf, bytebuf):
header: bytes = MAGIC_HEADER
else:
header: str = MAGIC_HEADER.decode("ascii")
if not buf.startswith(header):
raise ValueError("Not a valid JSONLZ4 buffer - magic bytes missing")
return json.loads(lz4.block.decompress(buf[len(header):]))
Код: Выделить всё
jsonlz4.py:18:27: error[invalid-argument-type] Argument to bound method `startswith` is incorrect: Expected `str | tuple[str, ...]`, found `Literal[b"mozLz40\x00"] | str`
jsonlz4.py:18:27: error[invalid-argument-type] Argument to bound method `startswith` is incorrect: Expected `Buffer | tuple[Buffer, ...]`, found `Literal[b"mozLz40\x00"] | str`
jsonlz4.py:18:27: error[invalid-argument-type] Argument to bound method `startswith` is incorrect: Expected `Buffer | tuple[Buffer, ...]`, found `Literal[b"mozLz40\x00"] | str`
Код: Выделить всё
pyrightКак мне добиться успешной проверки типа, не просто помечая как # тип: игнорировать?
Подробнее здесь: https://stackoverflow.com/questions/798 ... -str-bytes
Мобильная версия