Skip to content

Commit 489e830

Browse files
authored
Type obj parameter of PIL.Image.fromarray (#11176)
1 parent f11eb92 commit 489e830

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

stubs/Pillow/PIL/Image.pyi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ _Color: TypeAlias = (
3636
class _Writeable(SupportsWrite[bytes], Protocol):
3737
def seek(self, __offset: int) -> Any: ...
3838

39+
# Ref: https://numpy.org/doc/stable/reference/arrays.interface.html#python-side
40+
class _SupportsArrayInterface(Protocol):
41+
@property
42+
def __array_interface__(self) -> dict[str, Any]: ...
43+
3944
class DecompressionBombWarning(RuntimeWarning): ...
4045
class DecompressionBombError(Exception): ...
4146

@@ -294,7 +299,9 @@ class ImageTransformHandler: ...
294299
def new(mode: _Mode, size: tuple[int, int], color: _Color = 0) -> Image: ...
295300
def frombytes(mode: _Mode, size: tuple[int, int], data, decoder_name: str = "raw", *args) -> Image: ...
296301
def frombuffer(mode: _Mode, size: tuple[int, int], data, decoder_name: str = "raw", *args) -> Image: ...
297-
def fromarray(obj, mode: _Mode | None = None) -> Image: ...
302+
303+
# If the __array_interface__ has "strides", then `obj` must also support `tobytes` or `tostring`, but we can't enforce that
304+
def fromarray(obj: _SupportsArrayInterface, mode: _Mode | None = None) -> Image: ...
298305
def fromqimage(im) -> Image: ...
299306
def fromqpixmap(im) -> Image: ...
300307
def open(

0 commit comments

Comments
 (0)