diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index b4b3f71cb..df589e24a 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -1045,6 +1045,13 @@ class TestFileJpeg: assert im._repr_jpeg_() is None + def test_deprecation(self) -> None: + with Image.open(TEST_FILE) as im: + with pytest.warns(DeprecationWarning): + assert im.huffman_ac == {} + with pytest.warns(DeprecationWarning): + assert im.huffman_dc == {} + @pytest.mark.skipif(not is_win32(), reason="Windows only") @skip_unless_feature("jpg") diff --git a/docs/deprecations.rst b/docs/deprecations.rst index 2f5800e07..a03f274a9 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -118,6 +118,14 @@ The ``options`` parameter in :py:meth:`~PIL.ImageMath.lambda_eval()` and :py:meth:`~PIL.ImageMath.unsafe_eval()` has been deprecated. One or more keyword arguments can be used instead. +JpegImageFile.huffman_ac and JpegImageFile.huffman_dc +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. deprecated:: 11.0.0 + +The ``huffman_ac`` and ``huffman_dc`` dictionaries on JPEG images were unused, and have +been deprecated. + Removed features ---------------- diff --git a/docs/releasenotes/11.0.0.rst b/docs/releasenotes/11.0.0.rst index bb6179de8..579821ba9 100644 --- a/docs/releasenotes/11.0.0.rst +++ b/docs/releasenotes/11.0.0.rst @@ -50,6 +50,14 @@ The ``options`` parameter in :py:meth:`~PIL.ImageMath.lambda_eval()` and :py:meth:`~PIL.ImageMath.unsafe_eval()` has been deprecated. One or more keyword arguments can be used instead. +JpegImageFile.huffman_ac and JpegImageFile.huffman_dc +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. deprecated:: 11.0.0 + +The ``huffman_ac`` and ``huffman_dc`` dictionaries on JPEG images were unused, and have +been deprecated. + API Changes =========== diff --git a/src/PIL/JpegImagePlugin.py b/src/PIL/JpegImagePlugin.py index 3a83f9ca6..fc897e2b9 100644 --- a/src/PIL/JpegImagePlugin.py +++ b/src/PIL/JpegImagePlugin.py @@ -49,6 +49,7 @@ from ._binary import i16be as i16 from ._binary import i32be as i32 from ._binary import o8 from ._binary import o16be as o16 +from ._deprecate import deprecate from .JpegPresets import presets if TYPE_CHECKING: @@ -346,8 +347,8 @@ class JpegImageFile(ImageFile.ImageFile): # JPEG specifics (internal) self.layer: list[tuple[int, int, int, int]] = [] - self.huffman_dc: dict[Any, Any] = {} - self.huffman_ac: dict[Any, Any] = {} + self._huffman_dc: dict[Any, Any] = {} + self._huffman_ac: dict[Any, Any] = {} self.quantization: dict[int, list[int]] = {} self.app: dict[str, bytes] = {} # compatibility self.applist: list[tuple[str, bytes]] = [] @@ -386,6 +387,12 @@ class JpegImageFile(ImageFile.ImageFile): self._read_dpi_from_exif() + def __getattr__(self, name: str) -> Any: + if name in ("huffman_ac", "huffman_dc"): + deprecate(name, 12) + return getattr(self, "_" + name) + raise AttributeError(name) + def load_read(self, read_bytes: int) -> bytes: """ internal: read more image data