Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate ImagePalette size parameter #5641

Merged
merged 2 commits into from Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions Tests/test_imagepalette.py
Expand Up @@ -10,8 +10,9 @@ def test_sanity():
palette = ImagePalette.ImagePalette("RGB", list(range(256)) * 3)
assert len(palette.colors) == 256

with pytest.raises(ValueError):
ImagePalette.ImagePalette("RGB", list(range(256)) * 3, 10)
with pytest.warns(DeprecationWarning):
with pytest.raises(ValueError):
ImagePalette.ImagePalette("RGB", list(range(256)) * 3, 10)


def test_reload():
Expand Down
11 changes: 11 additions & 0 deletions docs/deprecations.rst
Expand Up @@ -92,6 +92,17 @@ dictionary. The :py:attr:`~PIL.JpegImagePlugin.convert_dict_qtables` method no l
performs any operations on the data given to it, has been deprecated and will be
removed in Pillow 10.0.0 (2023-01-02).

ImagePalette size parameter
~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. deprecated:: 8.4.0

The ``size`` parameter will be removed in Pillow 10.0.0 (2023-01-02).

Before Pillow 8.3.0, ImagePalette required palette data of particular lengths by
radarhere marked this conversation as resolved.
Show resolved Hide resolved
default, and the size parameter could be used to override that. Pillow 8.3.0 removed
the default required length, also removing the need for the size parameter.

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

Expand Down
11 changes: 9 additions & 2 deletions src/PIL/ImagePalette.py
Expand Up @@ -17,6 +17,7 @@
#

import array
import warnings

from . import GimpGradientFile, GimpPaletteFile, ImageColor, PaletteFile

Expand All @@ -40,8 +41,14 @@ def __init__(self, mode="RGB", palette=None, size=0):
self.rawmode = None # if set, palette contains raw data
self.palette = palette or bytearray()
self.dirty = None
if size != 0 and size != len(self.palette):
raise ValueError("wrong palette size")
if size != 0:
warnings.warn(
"The size parameter is deprecated and will be removed in Pillow 10 "
"(2023-01-02).",
DeprecationWarning,
)
if size != len(self.palette):
raise ValueError("wrong palette size")

@property
def palette(self):
Expand Down