Skip to content

Commit bcdb208

Browse files
committed
Restored Image constants, except for duplicate Resampling attributes
1 parent 2755e0f commit bcdb208

File tree

3 files changed

+14
-47
lines changed

3 files changed

+14
-47
lines changed

Tests/test_image.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -921,12 +921,7 @@ def test_categories_deprecation(self):
921921
with pytest.warns(DeprecationWarning):
922922
assert Image.CONTAINER == 2
923923

924-
def test_constants_deprecation(self):
925-
with pytest.warns(DeprecationWarning):
926-
assert Image.NEAREST == 0
927-
with pytest.warns(DeprecationWarning):
928-
assert Image.NONE == 0
929-
924+
def test_constants(self):
930925
with pytest.warns(DeprecationWarning):
931926
assert Image.LINEAR == Image.Resampling.BILINEAR
932927
with pytest.warns(DeprecationWarning):
@@ -943,8 +938,7 @@ def test_constants_deprecation(self):
943938
Image.Quantize,
944939
):
945940
for name in enum.__members__:
946-
with pytest.warns(DeprecationWarning):
947-
assert getattr(Image, name) == enum[name]
941+
assert getattr(Image, name) == enum[name]
948942

949943
@pytest.mark.parametrize(
950944
"path",

docs/deprecations.rst

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -77,37 +77,9 @@ A number of constants have been deprecated and will be removed in Pillow 10.0.0
7777
===================================================== ============================================================
7878
Deprecated Use instead
7979
===================================================== ============================================================
80-
``Image.NONE`` Either ``Image.Dither.NONE`` or ``Image.Resampling.NEAREST``
81-
``Image.NEAREST`` Either ``Image.Dither.NONE`` or ``Image.Resampling.NEAREST``
82-
``Image.ORDERED`` ``Image.Dither.ORDERED``
83-
``Image.RASTERIZE`` ``Image.Dither.RASTERIZE``
84-
``Image.FLOYDSTEINBERG`` ``Image.Dither.FLOYDSTEINBERG``
85-
``Image.WEB`` ``Image.Palette.WEB``
86-
``Image.ADAPTIVE`` ``Image.Palette.ADAPTIVE``
87-
``Image.AFFINE`` ``Image.Transform.AFFINE``
88-
``Image.EXTENT`` ``Image.Transform.EXTENT``
89-
``Image.PERSPECTIVE`` ``Image.Transform.PERSPECTIVE``
90-
``Image.QUAD`` ``Image.Transform.QUAD``
91-
``Image.MESH`` ``Image.Transform.MESH``
92-
``Image.FLIP_LEFT_RIGHT`` ``Image.Transpose.FLIP_LEFT_RIGHT``
93-
``Image.FLIP_TOP_BOTTOM`` ``Image.Transpose.FLIP_TOP_BOTTOM``
94-
``Image.ROTATE_90`` ``Image.Transpose.ROTATE_90``
95-
``Image.ROTATE_180`` ``Image.Transpose.ROTATE_180``
96-
``Image.ROTATE_270`` ``Image.Transpose.ROTATE_270``
97-
``Image.TRANSPOSE`` ``Image.Transpose.TRANSPOSE``
98-
``Image.TRANSVERSE`` ``Image.Transpose.TRANSVERSE``
99-
``Image.BOX`` ``Image.Resampling.BOX``
100-
``Image.BILINEAR`` ``Image.Resampling.BILINEAR``
101-
``Image.LINEAR`` ``Image.Resampling.BILINEAR``
102-
``Image.HAMMING`` ``Image.Resampling.HAMMING``
103-
``Image.BICUBIC`` ``Image.Resampling.BICUBIC``
104-
``Image.CUBIC`` ``Image.Resampling.BICUBIC``
105-
``Image.LANCZOS`` ``Image.Resampling.LANCZOS``
106-
``Image.ANTIALIAS`` ``Image.Resampling.LANCZOS``
107-
``Image.MEDIANCUT`` ``Image.Quantize.MEDIANCUT``
108-
``Image.MAXCOVERAGE`` ``Image.Quantize.MAXCOVERAGE``
109-
``Image.FASTOCTREE`` ``Image.Quantize.FASTOCTREE``
110-
``Image.LIBIMAGEQUANT`` ``Image.Quantize.LIBIMAGEQUANT``
80+
``Image.LINEAR`` ``Image.BILINEAR`` or ``Image.Resampling.BILINEAR``
81+
``Image.CUBIC`` ``Image.BICUBIC`` or ``Image.Resampling.BICUBIC``
82+
``Image.ANTIALIAS`` ``Image.LANCZOS`` or ``Image.Resampling.LANCZOS``
11183
``ImageCms.INTENT_PERCEPTUAL`` ``ImageCms.Intent.PERCEPTUAL``
11284
``ImageCms.INTENT_RELATIVE_COLORMETRIC`` ``ImageCms.Intent.RELATIVE_COLORMETRIC``
11385
``ImageCms.INTENT_SATURATION`` ``ImageCms.Intent.SATURATION``

src/PIL/Image.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,16 @@ def __getattr__(name):
6565
if name in categories:
6666
deprecate("Image categories", 10, "is_animated", plural=True)
6767
return categories[name]
68-
elif name in ("NEAREST", "NONE"):
69-
deprecate(name, 10, "Resampling.NEAREST or Dither.NONE")
70-
return 0
7168
old_resampling = {
7269
"LINEAR": "BILINEAR",
7370
"CUBIC": "BICUBIC",
7471
"ANTIALIAS": "LANCZOS",
7572
}
7673
if name in old_resampling:
77-
deprecate(name, 10, f"Resampling.{old_resampling[name]}")
74+
deprecate(
75+
name, 10, f"{old_resampling[name]} or Resampling.{old_resampling[name]}"
76+
)
7877
return Resampling[old_resampling[name]]
79-
for enum in (Transpose, Transform, Resampling, Dither, Palette, Quantize):
80-
if name in enum.__members__:
81-
deprecate(name, 10, f"{enum.__name__}.{name}")
82-
return enum[name]
8378
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
8479

8580

@@ -216,6 +211,12 @@ class Quantize(IntEnum):
216211
LIBIMAGEQUANT = 3
217212

218213

214+
module = sys.modules[__name__]
215+
for enum in (Transpose, Transform, Resampling, Dither, Palette, Quantize):
216+
for item in enum:
217+
setattr(module, item.name, item.value)
218+
219+
219220
if hasattr(core, "DEFAULT_STRATEGY"):
220221
DEFAULT_STRATEGY = core.DEFAULT_STRATEGY
221222
FILTERED = core.FILTERED

0 commit comments

Comments
 (0)