diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index b4b3f71cbb7..df589e24a1b 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -1045,6 +1045,13 @@ def test_repr_jpeg_error_returns_none(self) -> None: 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 2f5800e0711..058468cfe36 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. They +have been deprecated, and will be removed in Pillow 12 (2025-10-15). + Removed features ---------------- diff --git a/docs/releasenotes/11.0.0.rst b/docs/releasenotes/11.0.0.rst index bb6179de8c6..0175ae52d0d 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. They +have been deprecated, and will be removed in Pillow 12 (2025-10-15). + API Changes =========== diff --git a/src/PIL/JpegImagePlugin.py b/src/PIL/JpegImagePlugin.py index 3a83f9ca68a..fc897e2b919 100644 --- a/src/PIL/JpegImagePlugin.py +++ b/src/PIL/JpegImagePlugin.py @@ -49,6 +49,7 @@ 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 @@ def _open(self) -> None: # 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 @@ def _open(self) -> None: 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