From ce271355ad0e6a74cc3256167d3b9e7ef136a7e8 Mon Sep 17 00:00:00 2001 From: KG Date: Sat, 30 Dec 2023 17:10:48 -0500 Subject: [PATCH] Remove `ByteString` usages --- tivars/tokenizer/__init__.py | 4 +--- tivars/tokens | 2 +- tivars/types/list.py | 6 +++--- tivars/types/matrix.py | 4 ++-- tivars/types/tokenized.py | 5 ++--- tivars/var.py | 7 ++++--- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/tivars/tokenizer/__init__.py b/tivars/tokenizer/__init__.py index 5eb4ac3..c52c2ee 100644 --- a/tivars/tokenizer/__init__.py +++ b/tivars/tokenizer/__init__.py @@ -3,14 +3,12 @@ """ -from typing import ByteString - from tivars.data import String from tivars.models import * from tivars.tokens.scripts import * -def decode(bytestream: ByteString, *, +def decode(bytestream: bytes, *, tokens: Tokens = None, lang: str = "en", mode: str = "display") -> tuple[str | bytes, OsVersion]: tokens = tokens or TI_84PCE.tokens diff --git a/tivars/tokens b/tivars/tokens index a528d97..63867de 160000 --- a/tivars/tokens +++ b/tivars/tokens @@ -1 +1 @@ -Subproject commit a528d9726098f421a0dc491f79b933a87888f223 +Subproject commit 63867deb27e12b4a01a1a5fbb2d69ccd5ea62388 diff --git a/tivars/types/list.py b/tivars/types/list.py index 828b7ee..40fd6f1 100644 --- a/tivars/types/list.py +++ b/tivars/types/list.py @@ -6,7 +6,7 @@ import re from io import BytesIO -from typing import ByteString, Iterator, Sequence +from typing import Iterator, Sequence from warnings import warn from tivars.data import * @@ -88,7 +88,7 @@ class ListEntry(TIEntry): def __init__(self, init=None, *, for_flash: bool = True, name: str = "L1", version: int = None, archived: bool = None, - data: ByteString = None): + data: bytes = None): super().__init__(init, for_flash=for_flash, name=name, version=version, archived=archived, data=data) @@ -156,7 +156,7 @@ def get_version(self, data: bytes = None) -> int: def supported_by(self, model: TIModel) -> bool: return super().supported_by(model) and (self.get_version() <= 0x0B or model.has(TIFeature.ExactMath)) - @Loader[ByteString, BytesIO] + @Loader[bytes, bytearray, BytesIO] def load_bytes(self, data: bytes | BytesIO): super().load_bytes(data) diff --git a/tivars/types/matrix.py b/tivars/types/matrix.py index 5cb8495..55d8bf1 100644 --- a/tivars/types/matrix.py +++ b/tivars/types/matrix.py @@ -4,7 +4,7 @@ from io import BytesIO -from typing import ByteString, Iterator, Sequence +from typing import Iterator, Sequence from warnings import warn from tivars.data import * @@ -132,7 +132,7 @@ def get_version(self, data: bytes = None) -> int: def supported_by(self, model: TIModel) -> bool: return super().supported_by(model) and (self.get_version() <= 0x0B or model.has(TIFeature.ExactMath)) - @Loader[ByteString, BytesIO] + @Loader[bytes, bytearray, BytesIO] def load_bytes(self, data: bytes | BytesIO): super().load_bytes(data) diff --git a/tivars/types/tokenized.py b/tivars/types/tokenized.py index a0c2af5..5866947 100644 --- a/tivars/types/tokenized.py +++ b/tivars/types/tokenized.py @@ -6,7 +6,6 @@ import re from io import BytesIO -from typing import ByteString from warnings import warn from tivars.data import * @@ -133,7 +132,7 @@ def get_version(self, data: bytes = None) -> int: return version - @Loader[ByteString, BytesIO] + @Loader[bytes, bytearray, BytesIO] def load_bytes(self, data: bytes | BytesIO): super().load_bytes(data) @@ -348,7 +347,7 @@ def unprotect(self): self.type_id = 0x05 self.coerce() - @Loader[ByteString, BytesIO] + @Loader[bytes, bytearray, BytesIO] def load_bytes(self, data: bytes | BytesIO): super(TokenizedEntry, self).load_bytes(data) diff --git a/tivars/var.py b/tivars/var.py index 1f50aaf..ba0fa4a 100644 --- a/tivars/var.py +++ b/tivars/var.py @@ -4,7 +4,7 @@ from io import BytesIO -from typing import BinaryIO, ByteString, Iterator, Type +from typing import BinaryIO, Iterator, Type from warnings import warn from .data import * @@ -641,7 +641,7 @@ def unarchive(self): else: raise TypeError("entry does not support archiving.") - @Loader[ByteString, BytesIO] + @Loader[bytes, bytearray, BytesIO] def load_bytes(self, data: bytes | BytesIO): """ Loads a byte string or bytestream into this entry @@ -1192,7 +1192,8 @@ def clear(self): self.raw.calc_data.extend(bytearray(self.min_data_length - self.calc_data_length)) self.length = len(self.leading_bytes) + len(self.data) - def load_bytes(self, data: ByteString): + @Loader[bytes, bytearray, BytesIO] + def load_bytes(self, data: bytes | BytesIO): super().load_bytes(data) if self.length != (data_length := len(self.leading_bytes) + len(self.data)):