From 1e8cdf531b1b5c4a288b851e2b33f827c425c778 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Wed, 26 Jun 2024 09:51:16 -0500 Subject: [PATCH] add check for deprecated rawmodes when creating an ImagePalette --- Tests/test_imagepalette.py | 6 ++++++ src/PIL/ImagePalette.py | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/Tests/test_imagepalette.py b/Tests/test_imagepalette.py index 6cf0079dda7..0317f77de7a 100644 --- a/Tests/test_imagepalette.py +++ b/Tests/test_imagepalette.py @@ -158,6 +158,12 @@ def test_rawmode_valueerrors(tmp_path: Path) -> None: palette.save(f) +@pytest.mark.parametrize("rawmode", Image._DEPRECATED_RAWMODES) +def test_rawmode_deprecated(rawmode: str) -> None: + with pytest.warns(DeprecationWarning): + ImagePalette.raw(rawmode, b"") + + def test_getdata() -> None: # Arrange data_in = list(range(256)) * 3 diff --git a/src/PIL/ImagePalette.py b/src/PIL/ImagePalette.py index ed38285dc28..7466708a17b 100644 --- a/src/PIL/ImagePalette.py +++ b/src/PIL/ImagePalette.py @@ -208,6 +208,16 @@ def save(self, fp: str | IO[str]) -> None: def raw(rawmode, data: Sequence[int] | bytes | bytearray) -> ImagePalette: + from . import Image + from ._deprecate import deprecate + + if rawmode in Image._DEPRECATED_RAWMODES: + deprecate( + f"rawmode {rawmode}", + 12, + replacement=f"rawmode {Image._DEPRECATED_RAWMODES[rawmode]}", + ) + palette = ImagePalette() palette.rawmode = rawmode palette.palette = data