From 238110303c7bf829c0e56e5f721bcd80ad715699 Mon Sep 17 00:00:00 2001 From: Nulano Date: Wed, 12 Jun 2024 22:17:10 +0200 Subject: [PATCH] getpixel and putpixel also support a list argument --- src/PIL/Image.py | 6 ++++-- src/PIL/PyAccess.py | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 6dee3fe23..9c60bbb7a 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1676,7 +1676,7 @@ class Image: del self.info["transparency"] def getpixel( - self, xy: tuple[SupportsInt, SupportsInt] + self, xy: tuple[int, int] | list[int] ) -> float | tuple[int, ...] | None: """ Returns the pixel value at a given position. @@ -2058,7 +2058,9 @@ class Image: self.palette.mode = "RGB" self.load() # install new palette - def putpixel(self, xy: tuple[int, int], value: float | tuple[int, ...]) -> None: + def putpixel( + self, xy: tuple[int, int], value: float | tuple[int, ...] | list[int] + ) -> None: """ Modifies the pixel at the given position. The color is given as a single numerical value for single-band images, and a tuple for diff --git a/src/PIL/PyAccess.py b/src/PIL/PyAccess.py index 5663a7e48..d41f00aea 100644 --- a/src/PIL/PyAccess.py +++ b/src/PIL/PyAccess.py @@ -77,7 +77,11 @@ class PyAccess: def _post_init(self) -> None: pass - def __setitem__(self, xy: tuple[int, int], color: float | tuple[int, ...]) -> None: + def __setitem__( + self, + xy: tuple[int, int] | list[int], + color: float | tuple[int, ...] | list[int], + ) -> None: """ Modifies the pixel at x,y. The color is given as a single numerical value for single band images, and a tuple for @@ -112,7 +116,7 @@ class PyAccess: return self.set_pixel(x, y, color) - def __getitem__(self, xy: tuple[int, int]) -> float | tuple[int, ...]: + def __getitem__(self, xy: tuple[int, int] | list[int]) -> float | tuple[int, ...]: """ Returns the pixel at x,y. The pixel is returned as a single value for single band images or a tuple for multiple band