From e6fd8359d3184e09b8194c8ae8ec87c5a8c27c7f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 1 Aug 2024 12:27:45 +1000 Subject: [PATCH 1/2] Deprecate huffman_ac and huffman_dc --- Tests/test_file_jpeg.py | 7 +++++++ docs/deprecations.rst | 8 ++++++++ docs/releasenotes/11.0.0.rst | 8 ++++++++ src/PIL/JpegImagePlugin.py | 11 +++++++++-- 4 files changed, 32 insertions(+), 2 deletions(-) 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..a03f274a985 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 bb6179de8c6..579821ba904 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 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 From 488e1982bd8d1152c202652260ce8f239178c8f8 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 1 Aug 2024 16:29:46 +1000 Subject: [PATCH 2/2] Added removal version and date --- docs/deprecations.rst | 4 ++-- docs/releasenotes/11.0.0.rst | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/deprecations.rst b/docs/deprecations.rst index a03f274a985..058468cfe36 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -123,8 +123,8 @@ 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. +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 579821ba904..0175ae52d0d 100644 --- a/docs/releasenotes/11.0.0.rst +++ b/docs/releasenotes/11.0.0.rst @@ -55,8 +55,8 @@ 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. +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 ===========