mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-19 12:42:27 +03:00
Added type hints
This commit is contained in:
parent
78887f6114
commit
6807bd3d70
|
@ -4,6 +4,7 @@ IceSpringPySideStubs-PySide6
|
||||||
ipython
|
ipython
|
||||||
numpy
|
numpy
|
||||||
packaging
|
packaging
|
||||||
|
pyarrow-stubs
|
||||||
pytest
|
pytest
|
||||||
sphinx
|
sphinx
|
||||||
types-atheris
|
types-atheris
|
||||||
|
|
|
@ -13,7 +13,11 @@ from .helper import (
|
||||||
is_big_endian,
|
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)
|
TEST_IMAGE_SIZE = (10, 10)
|
||||||
|
|
||||||
|
@ -94,14 +98,14 @@ fl_uint8_4_type = pyarrow.field(
|
||||||
("HSV", fl_uint8_4_type, [0, 1, 2]),
|
("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)
|
img = hopper(mode)
|
||||||
|
|
||||||
# Resize to non-square
|
# Resize to non-square
|
||||||
img = img.crop((3, 0, 124, 127))
|
img = img.crop((3, 0, 124, 127))
|
||||||
assert img.size == (121, 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)
|
_test_img_equals_pyarray(img, arr, mask)
|
||||||
assert arr.type == dtype
|
assert arr.type == dtype
|
||||||
|
|
||||||
|
@ -118,8 +122,8 @@ def test_lifetime() -> None:
|
||||||
|
|
||||||
img = hopper("L")
|
img = hopper("L")
|
||||||
|
|
||||||
arr_1 = pyarrow.array(img)
|
arr_1 = pyarrow.array(img) # type: ignore[call-overload]
|
||||||
arr_2 = pyarrow.array(img)
|
arr_2 = pyarrow.array(img) # type: ignore[call-overload]
|
||||||
|
|
||||||
del img
|
del img
|
||||||
|
|
||||||
|
@ -136,8 +140,8 @@ def test_lifetime2() -> None:
|
||||||
|
|
||||||
img = hopper("L")
|
img = hopper("L")
|
||||||
|
|
||||||
arr_1 = pyarrow.array(img)
|
arr_1 = pyarrow.array(img) # type: ignore[call-overload]
|
||||||
arr_2 = pyarrow.array(img)
|
arr_2 = pyarrow.array(img) # type: ignore[call-overload]
|
||||||
|
|
||||||
assert arr_1.sum().as_py() > 0
|
assert arr_1.sum().as_py() > 0
|
||||||
del arr_1
|
del arr_1
|
||||||
|
@ -152,7 +156,7 @@ def test_lifetime2() -> None:
|
||||||
|
|
||||||
|
|
||||||
class DataShape(NamedTuple):
|
class DataShape(NamedTuple):
|
||||||
dtype: Any
|
dtype: pyarrow.DataType
|
||||||
# Strictly speaking, elt should be a pixel or pixel component, so
|
# Strictly speaking, elt should be a pixel or pixel component, so
|
||||||
# list[uint8][4], float, int, uint32, uint8, etc. But more
|
# list[uint8][4], float, int, uint32, uint8, etc. But more
|
||||||
# correctly, it should be exactly the dtype from the line above.
|
# correctly, it should be exactly the dtype from the line above.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user