Skip to content

Commit

Permalink
Merge pull request #6830 from radarhere/enum
Browse files Browse the repository at this point in the history
Removed deprecations for Image constants, except for duplicate Resampling attributes
  • Loading branch information
mergify[bot] committed Dec 31, 2022
2 parents 907d597 + 559b7ae commit fc9a8a3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 47 deletions.
10 changes: 2 additions & 8 deletions Tests/test_image.py
Expand Up @@ -921,12 +921,7 @@ def test_categories_deprecation(self):
with pytest.warns(DeprecationWarning):
assert Image.CONTAINER == 2

def test_constants_deprecation(self):
with pytest.warns(DeprecationWarning):
assert Image.NEAREST == 0
with pytest.warns(DeprecationWarning):
assert Image.NONE == 0

def test_constants(self):
with pytest.warns(DeprecationWarning):
assert Image.LINEAR == Image.Resampling.BILINEAR
with pytest.warns(DeprecationWarning):
Expand All @@ -943,8 +938,7 @@ def test_constants_deprecation(self):
Image.Quantize,
):
for name in enum.__members__:
with pytest.warns(DeprecationWarning):
assert getattr(Image, name) == enum[name]
assert getattr(Image, name) == enum[name]

@pytest.mark.parametrize(
"path",
Expand Down
40 changes: 9 additions & 31 deletions docs/deprecations.rst
Expand Up @@ -74,40 +74,18 @@ Constants
A number of constants have been deprecated and will be removed in Pillow 10.0.0
(2023-07-01). Instead, ``enum.IntEnum`` classes have been added.

.. note::

Additional ``Image`` constants were deprecated in Pillow 9.1.0, but that
was reversed in Pillow 9.4.0 and those constants will now remain available.
See :ref:`restored-image-constants`

===================================================== ============================================================
Deprecated Use instead
===================================================== ============================================================
``Image.NONE`` Either ``Image.Dither.NONE`` or ``Image.Resampling.NEAREST``
``Image.NEAREST`` Either ``Image.Dither.NONE`` or ``Image.Resampling.NEAREST``
``Image.ORDERED`` ``Image.Dither.ORDERED``
``Image.RASTERIZE`` ``Image.Dither.RASTERIZE``
``Image.FLOYDSTEINBERG`` ``Image.Dither.FLOYDSTEINBERG``
``Image.WEB`` ``Image.Palette.WEB``
``Image.ADAPTIVE`` ``Image.Palette.ADAPTIVE``
``Image.AFFINE`` ``Image.Transform.AFFINE``
``Image.EXTENT`` ``Image.Transform.EXTENT``
``Image.PERSPECTIVE`` ``Image.Transform.PERSPECTIVE``
``Image.QUAD`` ``Image.Transform.QUAD``
``Image.MESH`` ``Image.Transform.MESH``
``Image.FLIP_LEFT_RIGHT`` ``Image.Transpose.FLIP_LEFT_RIGHT``
``Image.FLIP_TOP_BOTTOM`` ``Image.Transpose.FLIP_TOP_BOTTOM``
``Image.ROTATE_90`` ``Image.Transpose.ROTATE_90``
``Image.ROTATE_180`` ``Image.Transpose.ROTATE_180``
``Image.ROTATE_270`` ``Image.Transpose.ROTATE_270``
``Image.TRANSPOSE`` ``Image.Transpose.TRANSPOSE``
``Image.TRANSVERSE`` ``Image.Transpose.TRANSVERSE``
``Image.BOX`` ``Image.Resampling.BOX``
``Image.BILINEAR`` ``Image.Resampling.BILINEAR``
``Image.LINEAR`` ``Image.Resampling.BILINEAR``
``Image.HAMMING`` ``Image.Resampling.HAMMING``
``Image.BICUBIC`` ``Image.Resampling.BICUBIC``
``Image.CUBIC`` ``Image.Resampling.BICUBIC``
``Image.LANCZOS`` ``Image.Resampling.LANCZOS``
``Image.ANTIALIAS`` ``Image.Resampling.LANCZOS``
``Image.MEDIANCUT`` ``Image.Quantize.MEDIANCUT``
``Image.MAXCOVERAGE`` ``Image.Quantize.MAXCOVERAGE``
``Image.FASTOCTREE`` ``Image.Quantize.FASTOCTREE``
``Image.LIBIMAGEQUANT`` ``Image.Quantize.LIBIMAGEQUANT``
``Image.LINEAR`` ``Image.BILINEAR`` or ``Image.Resampling.BILINEAR``
``Image.CUBIC`` ``Image.BICUBIC`` or ``Image.Resampling.BICUBIC``
``Image.ANTIALIAS`` ``Image.LANCZOS`` or ``Image.Resampling.LANCZOS``
``ImageCms.INTENT_PERCEPTUAL`` ``ImageCms.Intent.PERCEPTUAL``
``ImageCms.INTENT_RELATIVE_COLORMETRIC`` ``ImageCms.Intent.RELATIVE_COLORMETRIC``
``ImageCms.INTENT_SATURATION`` ``ImageCms.Intent.SATURATION``
Expand Down
5 changes: 5 additions & 0 deletions docs/releasenotes/9.1.0.rst
Expand Up @@ -53,6 +53,11 @@ Constants
A number of constants have been deprecated and will be removed in Pillow 10.0.0
(2023-07-01). Instead, ``enum.IntEnum`` classes have been added.

.. note::

Some of these deprecations were restored in Pillow 9.4.0. See
:ref:`restored-image-constants`

===================================================== ============================================================
Deprecated Use instead
===================================================== ============================================================
Expand Down
37 changes: 37 additions & 0 deletions docs/releasenotes/9.4.0.rst
Expand Up @@ -109,3 +109,40 @@ Added support for DDS L and LA images

Support has been added to read and write L and LA DDS images in the uncompressed
format, known as "luminance" textures.

.. _restored-image-constants:

Constants
^^^^^^^^^

In Pillow 9.1.0, the following constants were deprecated. That has been reversed and
these constants will now remain available.

- ``Image.NONE``
- ``Image.NEAREST``
- ``Image.ORDERED``
- ``Image.RASTERIZE``
- ``Image.FLOYDSTEINBERG``
- ``Image.WEB``
- ``Image.ADAPTIVE``
- ``Image.AFFINE``
- ``Image.EXTENT``
- ``Image.PERSPECTIVE``
- ``Image.QUAD``
- ``Image.MESH``
- ``Image.FLIP_LEFT_RIGHT``
- ``Image.FLIP_TOP_BOTTOM``
- ``Image.ROTATE_90``
- ``Image.ROTATE_180``
- ``Image.ROTATE_270``
- ``Image.TRANSPOSE``
- ``Image.TRANSVERSE``
- ``Image.BOX``
- ``Image.BILINEAR``
- ``Image.HAMMING``
- ``Image.BICUBIC``
- ``Image.LANCZOS``
- ``Image.MEDIANCUT``
- ``Image.MAXCOVERAGE``
- ``Image.FASTOCTREE``
- ``Image.LIBIMAGEQUANT``
17 changes: 9 additions & 8 deletions src/PIL/Image.py
Expand Up @@ -65,21 +65,16 @@ def __getattr__(name):
if name in categories:
deprecate("Image categories", 10, "is_animated", plural=True)
return categories[name]
elif name in ("NEAREST", "NONE"):
deprecate(name, 10, "Resampling.NEAREST or Dither.NONE")
return 0
old_resampling = {
"LINEAR": "BILINEAR",
"CUBIC": "BICUBIC",
"ANTIALIAS": "LANCZOS",
}
if name in old_resampling:
deprecate(name, 10, f"Resampling.{old_resampling[name]}")
deprecate(
name, 10, f"{old_resampling[name]} or Resampling.{old_resampling[name]}"
)
return Resampling[old_resampling[name]]
for enum in (Transpose, Transform, Resampling, Dither, Palette, Quantize):
if name in enum.__members__:
deprecate(name, 10, f"{enum.__name__}.{name}")
return enum[name]
msg = f"module '{__name__}' has no attribute '{name}'"
raise AttributeError(msg)

Expand Down Expand Up @@ -218,6 +213,12 @@ class Quantize(IntEnum):
LIBIMAGEQUANT = 3


module = sys.modules[__name__]
for enum in (Transpose, Transform, Resampling, Dither, Palette, Quantize):
for item in enum:
setattr(module, item.name, item.value)


if hasattr(core, "DEFAULT_STRATEGY"):
DEFAULT_STRATEGY = core.DEFAULT_STRATEGY
FILTERED = core.FILTERED
Expand Down

0 comments on commit fc9a8a3

Please sign in to comment.