From 2f22696151901610dfc9a3d2686c387438918f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20N=C3=B8rgaard?= Date: Fri, 13 Jan 2023 03:25:44 +0000 Subject: [PATCH] remove `Literal` string types for struct (un)pack --- a2s/byteio.py | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/a2s/byteio.py b/a2s/byteio.py index cbbe95f..f747a2c 100644 --- a/a2s/byteio.py +++ b/a2s/byteio.py @@ -2,37 +2,10 @@ from __future__ import annotations import io import struct -from typing import TYPE_CHECKING, Any, Optional, Tuple, Union +from typing import Any, Optional, Tuple, Union from a2s.exceptions import BufferExhaustedError -if TYPE_CHECKING: - from typing_extensions import Literal - -STRUCT_OPTIONS = Literal[ - "x", - "c", - "b", - "B", - "?", - "h", - "H", - "i", - "I", - "l", - "L", - "q", - "Q", - "n", - "N", - "e", - "f", - "d", - "s", - "p", - "P", -] - class ByteReader: __slots__ = ( @@ -64,12 +37,12 @@ class ByteReader: self.stream.seek(cur_pos, io.SEEK_SET) return data - def unpack(self, fmt: STRUCT_OPTIONS) -> Tuple[Any, ...]: + def unpack(self, fmt: str) -> Tuple[Any, ...]: new_fmt = self.endian + fmt fmt_size = struct.calcsize(fmt) return struct.unpack(new_fmt, self.read(fmt_size)) - def unpack_one(self, fmt: STRUCT_OPTIONS) -> Any: + def unpack_one(self, fmt: str) -> Any: values = self.unpack(fmt) assert len(values) == 1 return values[0]