Skip to content

Commit f08bed0

Browse files
committed
Using Sequence type hints for iterables
1 parent ea80ebb commit f08bed0

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed

tivars/types/group.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import io
22

3+
from typing import Sequence
34
from warnings import warn
45

56
from tivars.models import *
@@ -37,9 +38,9 @@ def __init__(self, init=None, *,
3738
super().__init__(init, for_flash=for_flash, name=name, version=version, archived=archived, data=data)
3839

3940
@staticmethod
40-
def group(entries: list[TIEntry], *, name: str = "GROUP") -> 'TIGroup':
41+
def group(entries: Sequence[TIEntry], *, name: str = "GROUP") -> 'TIGroup':
4142
"""
42-
Creates a new `TIGroup` by packaging a ``list`` of entries using defaulted VAT data
43+
Creates a new `TIGroup` by packaging a sequence of entries using defaulted VAT data
4344
4445
:param entries: The entries to group
4546
:param name: The name of the group (defaults to ``GROUP``)
@@ -145,10 +146,10 @@ def ungroup(self, data: bytes = None) -> list[TIEntry]:
145146

146147
return entries
147148

148-
@Loader[list]
149-
def load_from_entries(self, entries: list[TIEntry]):
149+
@Loader[Sequence]
150+
def load_from_entries(self, entries: Sequence[TIEntry]):
150151
"""
151-
Loads a ``list`` of entries into this group
152+
Loads a sequence of entries into this group
152153
153154
All VAT data is cleared.
154155

tivars/types/list.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22

33
from io import BytesIO
4-
from typing import ByteString, Iterator
4+
from typing import ByteString, Iterator, Sequence
55
from warnings import warn
66

77
from tivars.models import *
@@ -160,10 +160,10 @@ def load_bytes(self, data: bytes | BytesIO):
160160
f"(expected {self.calc_data_length // self._E.min_data_length}, got {self.length}).",
161161
BytesWarning)
162162

163-
@Loader[list]
164-
def load_list(self, lst: list[_E]):
163+
@Loader[Sequence]
164+
def load_list(self, lst: Sequence[_E]):
165165
"""
166-
Loads a ``list`` into this list
166+
Loads a sequence into this list
167167
168168
:param lst: The list to load
169169
"""

tivars/types/matrix.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from io import BytesIO
2-
from typing import ByteString, Iterator
2+
from typing import ByteString, Iterator, Sequence
33
from warnings import warn
44

55
from tivars.models import *
@@ -141,10 +141,10 @@ def load_data_section(self, data: BytesIO):
141141
height = int.from_bytes(height_byte := data.read(1), 'little')
142142
self.raw.calc_data = bytearray(width_byte + height_byte + data.read(width * height))
143143

144-
@Loader[list]
145-
def load_matrix(self, matrix: list[list[RealEntry]]):
144+
@Loader[Sequence]
145+
def load_matrix(self, matrix: Sequence[Sequence[RealEntry]]):
146146
"""
147-
Loads a two-dimensional ``list`` into this matrix
147+
Loads a two-dimensional sequence into this matrix
148148
149149
:param matrix: The matrix to load
150150
"""

tivars/types/picture.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Iterator
1+
from typing import Iterator, Sequence
22
from warnings import warn
33

44
from tivars.models import *
@@ -192,10 +192,10 @@ def __iter__(self) -> Iterator[pixel_type]:
192192
for col in row:
193193
yield col
194194

195-
@Loader[list, ]
196-
def load_array(self, arr: list[list[pixel_type]]):
195+
@Loader[Sequence]
196+
def load_array(self, arr: Sequence[Sequence[pixel_type]]):
197197
"""
198-
Loads a two-dimensional ``list`` of pixels into this picture
198+
Loads a two-dimensional sequence of pixels into this picture
199199
200200
:param arr: The array to load
201201
"""
@@ -257,8 +257,8 @@ def __init__(self, init=None, *,
257257
def get_min_os(self, data: bytes = None) -> OsVersion:
258258
return TI_83P.OS()
259259

260-
@Loader[list]
261-
def load_array(self, arr: list[list[pixel_type]]):
260+
@Loader[Sequence]
261+
def load_array(self, arr: Sequence[Sequence[pixel_type]]):
262262
self.data = b''.join(L1.set(entry) for row in arr for entry in zip(*[iter(row)] * 8, strict=True))
263263

264264
def array(self) -> list[list[pixel_type]]:
@@ -308,8 +308,8 @@ def __init__(self, init=None, *,
308308
def get_min_os(self, data: bytes = None) -> OsVersion:
309309
return TI_84PCSE.OS()
310310

311-
@Loader[list]
312-
def load_array(self, arr: list[list[pixel_type]]):
311+
@Loader[Sequence]
312+
def load_array(self, arr: Sequence[Sequence[pixel_type]]):
313313
self.data = b''.join(RGBPalette.set(entry) for row in arr for entry in zip(row[::2], row[1::2]))
314314

315315
def array(self) -> list[list[pixel_type]]:
@@ -400,8 +400,8 @@ def data(self) -> bytes:
400400
def get_min_os(self, data: bytes = None) -> OsVersion:
401401
return TI_84PCSE.OS()
402402

403-
@Loader[list]
404-
def load_array(self, arr: list[list[pixel_type]]):
403+
@Loader[Sequence]
404+
def load_array(self, arr: Sequence[Sequence[pixel_type]]):
405405
self.data = b''.join(RGB565.set(entry) for row in arr[::-1] for entry in row + [(0, 0, 0)])
406406

407407
def array(self) -> list[list[pixel_type]]:

0 commit comments

Comments
 (0)