Deprecate huffman_ac and huffman_dc

This commit is contained in:
Andrew Murray 2024-08-01 12:27:45 +10:00
parent 4df4df2a18
commit e6fd8359d3
4 changed files with 32 additions and 2 deletions

View File

@ -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")

View File

@ -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
----------------

View File

@ -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
===========

View File

@ -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