Added type hints

This commit is contained in:
Andrew Murray 2025-05-10 00:03:08 +10:00 committed by wiredfool
parent 78887f6114
commit 6807bd3d70
2 changed files with 13 additions and 8 deletions

View File

@ -4,6 +4,7 @@ IceSpringPySideStubs-PySide6
ipython
numpy
packaging
pyarrow-stubs
pytest
sphinx
types-atheris

View File

@ -13,7 +13,11 @@ from .helper import (
is_big_endian,
)
pyarrow = pytest.importorskip("pyarrow", reason="PyArrow not installed")
TYPE_CHECKING = False
if TYPE_CHECKING:
import pyarrow
else:
pyarrow = pytest.importorskip("pyarrow", reason="PyArrow not installed")
TEST_IMAGE_SIZE = (10, 10)
@ -94,14 +98,14 @@ fl_uint8_4_type = pyarrow.field(
("HSV", fl_uint8_4_type, [0, 1, 2]),
),
)
def test_to_array(mode: str, dtype: Any, mask: list[int] | None) -> None:
def test_to_array(mode: str, dtype: pyarrow.DataType, mask: list[int] | None) -> None:
img = hopper(mode)
# Resize to non-square
img = img.crop((3, 0, 124, 127))
assert img.size == (121, 127)
arr = pyarrow.array(img)
arr = pyarrow.array(img) # type: ignore[call-overload]
_test_img_equals_pyarray(img, arr, mask)
assert arr.type == dtype
@ -118,8 +122,8 @@ def test_lifetime() -> None:
img = hopper("L")
arr_1 = pyarrow.array(img)
arr_2 = pyarrow.array(img)
arr_1 = pyarrow.array(img) # type: ignore[call-overload]
arr_2 = pyarrow.array(img) # type: ignore[call-overload]
del img
@ -136,8 +140,8 @@ def test_lifetime2() -> None:
img = hopper("L")
arr_1 = pyarrow.array(img)
arr_2 = pyarrow.array(img)
arr_1 = pyarrow.array(img) # type: ignore[call-overload]
arr_2 = pyarrow.array(img) # type: ignore[call-overload]
assert arr_1.sum().as_py() > 0
del arr_1
@ -152,7 +156,7 @@ def test_lifetime2() -> None:
class DataShape(NamedTuple):
dtype: Any
dtype: pyarrow.DataType
# Strictly speaking, elt should be a pixel or pixel component, so
# list[uint8][4], float, int, uint32, uint8, etc. But more
# correctly, it should be exactly the dtype from the line above.