diff --git a/Tests/test_image_access.py b/Tests/test_image_access.py index ee8a92d5eaf..c82c9e1d157 100644 --- a/Tests/test_image_access.py +++ b/Tests/test_image_access.py @@ -119,6 +119,11 @@ def test_numpy(self) -> None: assert numpy is not None assert px[numpy.int32(1), numpy.int32(2)] == (18, 20, 59) + def test_deprecation(self) -> None: + im = Image.new("PA", (1, 1)) + with pytest.warns(DeprecationWarning, match="'value' lists"): + im.putpixel((0, 0), [0, 0, 0]) # type: ignore[arg-type] + class TestImageGetPixel: @staticmethod diff --git a/docs/deprecations.rst b/docs/deprecations.rst index 185a5927c70..3e106883d8d 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -31,6 +31,14 @@ The IM image format has been deprecated and removal is planned in Pillow 15.0.0 (2028-10-15). If you are using this format and would like to continue doing so, open an issue about what other software uses it. +Image.putpixel 'value' lists +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. deprecated:: 13.0.0 + +Passing lists to the ``value`` parameter of :py:meth:`~PIL.Image.Image.putpixel` have +been deprecated. Use tuples instead. + ImageQt align8to32() ^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/releasenotes/13.0.0.rst b/docs/releasenotes/13.0.0.rst index 46dbed3b58b..15c2b525a23 100644 --- a/docs/releasenotes/13.0.0.rst +++ b/docs/releasenotes/13.0.0.rst @@ -81,6 +81,12 @@ The IM image format has been deprecated and removal is planned in Pillow 15.0.0 (2028-10-15). If you are using this format and would like to continue doing so, open an issue about what other software uses it. +Image.putpixel 'value' lists +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Passing lists to the ``value`` parameter of :py:meth:`~PIL.Image.Image.putpixel` have +been deprecated. Use tuples instead. + JpegImageFile.load_djpeg ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 82e71035787..0e9e556050d 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2183,7 +2183,7 @@ def putpalette( def putpixel( self, xy: tuple[int, int] | list[int], - value: float | tuple[int, ...] | list[int], + value: float | tuple[int, ...], ) -> None: """ Modifies the pixel at the given position. The color is given as @@ -2213,6 +2213,9 @@ def putpixel( and isinstance(value, (list, tuple)) and len(value) in [3, 4] ): + if isinstance(value, list): # type: ignore[unreachable] + deprecate("'value' lists", 14, "tuples", plural=True) # type: ignore[unreachable] + # RGB or RGBA value for a P or PA image if self.mode == "PA": alpha = value[3] if len(value) == 4 else 255