diff --git a/stubs/Pillow/PIL/Image.pyi b/stubs/Pillow/PIL/Image.pyi index f42ca9554..18fb5c63c 100644 --- a/stubs/Pillow/PIL/Image.pyi +++ b/stubs/Pillow/PIL/Image.pyi @@ -36,6 +36,11 @@ _Color: TypeAlias = ( class _Writeable(SupportsWrite[bytes], Protocol): def seek(self, __offset: int) -> Any: ... +# Ref: https://numpy.org/doc/stable/reference/arrays.interface.html#python-side +class _SupportsArrayInterface(Protocol): + @property + def __array_interface__(self) -> dict[str, Any]: ... + class DecompressionBombWarning(RuntimeWarning): ... class DecompressionBombError(Exception): ... @@ -294,7 +299,9 @@ class ImageTransformHandler: ... def new(mode: _Mode, size: tuple[int, int], color: _Color = 0) -> Image: ... def frombytes(mode: _Mode, size: tuple[int, int], data, decoder_name: str = "raw", *args) -> Image: ... def frombuffer(mode: _Mode, size: tuple[int, int], data, decoder_name: str = "raw", *args) -> Image: ... -def fromarray(obj, mode: _Mode | None = None) -> Image: ... + +# If the __array_interface__ has "strides", then `obj` must also support `tobytes` or `tostring`, but we can't enforce that +def fromarray(obj: _SupportsArrayInterface, mode: _Mode | None = None) -> Image: ... def fromqimage(im) -> Image: ... def fromqpixmap(im) -> Image: ... def open(