Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Tests/test_image_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,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
Expand Down
8 changes: 8 additions & 0 deletions docs/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ Image getdata()
identical, except that it returns a tuple of pixel values, instead of an internal
Pillow data type.

Image.putpixel 'value' lists
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. deprecated:: 12.3.0

Passing lists to the ``value`` parameter of :py:meth:`~PIL.Image.Image.putpixel` have
been deprecated. Use tuples instead.

Removed features
----------------

Expand Down
9 changes: 6 additions & 3 deletions docs/releasenotes/12.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ TODO
Deprecations
============

TODO
^^^^
Image.putpixel 'value' lists
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

TODO
.. deprecated:: 12.3.0

Passing lists to the ``value`` parameter of :py:meth:`~PIL.Image.Image.putpixel` have
been deprecated. Use tuples instead.

API changes
===========
Expand Down
7 changes: 4 additions & 3 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2173,9 +2173,7 @@ def putpalette(
self.palette.mode = "RGB"
self.load() # install new palette

def putpixel(
self, xy: tuple[int, int], value: float | tuple[int, ...] | list[int]
) -> None:
def putpixel(self, xy: tuple[int, int], value: float | tuple[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
Expand Down Expand Up @@ -2204,6 +2202,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
Expand Down