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

Rename 16-bit RGB rawmodes #8158

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
add check for deprecated rawmodes when creating an ImagePalette
  • Loading branch information
Yay295 committed Oct 12, 2024
commit 75e54c23acf695aa0eb568143f4cb6d89eb825cb
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 @@ -209,6 +209,16 @@ def save(self, fp: str | IO[str]) -> None:


def raw(rawmode: str, 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