[basic] cast to the expected types before conversion

This commit is contained in:
Jan Petykiewicz 2026-02-15 16:25:21 -08:00
commit 5b42cdf609

View file

@ -2,7 +2,7 @@
This module contains all datatypes and parsing/writing functions for
all abstractions below the 'record' or 'block' level.
"""
from typing import Any, IO, Union
from typing import Any, IO, Union, TYPE_CHECKING
from collections.abc import Sequence
from fractions import Fraction
from enum import Enum
@ -250,6 +250,7 @@ def write_uint(stream: IO[bytes], n: int) -> int:
Raises:
SignedError: if `n` is negative.
"""
n = int(n)
if n < 0:
raise SignedError(f'uint must be positive: {n}')
@ -295,6 +296,7 @@ def encode_sint(sint: int) -> int:
Returns:
Unsigned integer encoding for the input.
"""
sint = int(sint)
return (abs(sint) << 1) | (sint < 0)
@ -1595,7 +1597,7 @@ def read_point_list(
def write_point_list(
stream: IO[bytes],
points: list[Sequence[int]],
points: 'list[Sequence[int]] | NDArray',
fast: bool = False,
implicit_closed: bool = True
) -> int:
@ -1618,6 +1620,8 @@ def write_point_list(
Number of bytes written.
"""
# If we're in a hurry, just write the points as arbitrary Deltas
if _USE_NUMPY:
points = numpy.asarray(points, dtype=int)
if fast:
size = write_uint(stream, 4)
size += write_uint(stream, len(points))