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