Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reversed deprecations for Image constants, except for duplicate Resampling attributes #6830

Merged
merged 4 commits into from Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
39 changes: 8 additions & 31 deletions docs/deprecations.rst
Expand Up @@ -74,40 +74,17 @@ 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 they
were later restored in Pillow 9.4.0. 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 @@ -103,3 +103,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. Those deprecations have now
been restored.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if something like this is clearer?

Suggested change
In Pillow 9.1.0, the following constants were deprecated. Those deprecations have now
been restored.
In Pillow 9.1.0, the following constants were deprecated.
That has been reversed and these constants will now remain available.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sure. I've pushed a commit changing that, and the text in deprecations.rst.


- ``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]
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")


Expand Down Expand Up @@ -216,6 +211,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