Skip to content

Commit

Permalink
add check for deprecated rawmodes when creating an ImagePalette
Browse files Browse the repository at this point in the history
  • Loading branch information
Yay295 committed Jun 27, 2024
1 parent b74ff65 commit b3c6eac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Tests/test_imagepalette.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/PIL/ImagePalette.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b3c6eac

Please sign in to comment.