Skip to content

Commit dcd2025

Browse files
authored
Remove deprecations for Pillow 12.0.0 (#9053)
2 parents dc9e0cf + f2417d8 commit dcd2025

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+316
-865
lines changed

Tests/helper.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,13 @@ def _cached_hopper(mode: str) -> Image.Image:
271271
im = hopper("L")
272272
else:
273273
im = hopper()
274-
if mode.startswith("BGR;"):
275-
with pytest.warns(DeprecationWarning, match="BGR;"):
276-
im = im.convert(mode)
277-
else:
278-
try:
279-
im = im.convert(mode)
280-
except ImportError:
281-
if mode == "LAB":
282-
im = Image.open("Tests/images/hopper.Lab.tif")
283-
else:
284-
raise
274+
try:
275+
im = im.convert(mode)
276+
except ImportError:
277+
if mode == "LAB":
278+
im = Image.open("Tests/images/hopper.Lab.tif")
279+
else:
280+
raise
285281
return im
286282

287283

Tests/test_deprecate.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"version, expected",
1010
[
1111
(
12-
12,
13-
"Old thing is deprecated and will be removed in Pillow 12 "
14-
r"\(2025-10-15\)\. Use new thing instead\.",
12+
13,
13+
"Old thing is deprecated and will be removed in Pillow 13 "
14+
r"\(2026-10-15\)\. Use new thing instead\.",
1515
),
1616
(
1717
None,
@@ -53,18 +53,18 @@ def test_old_version(deprecated: str, plural: bool, expected: str) -> None:
5353

5454
def test_plural() -> None:
5555
expected = (
56-
r"Old things are deprecated and will be removed in Pillow 12 \(2025-10-15\)\. "
56+
r"Old things are deprecated and will be removed in Pillow 13 \(2026-10-15\)\. "
5757
r"Use new thing instead\."
5858
)
5959
with pytest.warns(DeprecationWarning, match=expected):
60-
_deprecate.deprecate("Old things", 12, "new thing", plural=True)
60+
_deprecate.deprecate("Old things", 13, "new thing", plural=True)
6161

6262

6363
def test_replacement_and_action() -> None:
6464
expected = "Use only one of 'replacement' and 'action'"
6565
with pytest.raises(ValueError, match=expected):
6666
_deprecate.deprecate(
67-
"Old thing", 12, replacement="new thing", action="Upgrade to new thing"
67+
"Old thing", 13, replacement="new thing", action="Upgrade to new thing"
6868
)
6969

7070

@@ -77,16 +77,16 @@ def test_replacement_and_action() -> None:
7777
)
7878
def test_action(action: str) -> None:
7979
expected = (
80-
r"Old thing is deprecated and will be removed in Pillow 12 \(2025-10-15\)\. "
80+
r"Old thing is deprecated and will be removed in Pillow 13 \(2026-10-15\)\. "
8181
r"Upgrade to new thing\."
8282
)
8383
with pytest.warns(DeprecationWarning, match=expected):
84-
_deprecate.deprecate("Old thing", 12, action=action)
84+
_deprecate.deprecate("Old thing", 13, action=action)
8585

8686

8787
def test_no_replacement_or_action() -> None:
8888
expected = (
89-
r"Old thing is deprecated and will be removed in Pillow 12 \(2025-10-15\)"
89+
r"Old thing is deprecated and will be removed in Pillow 13 \(2026-10-15\)"
9090
)
9191
with pytest.warns(DeprecationWarning, match=expected):
92-
_deprecate.deprecate("Old thing", 12)
92+
_deprecate.deprecate("Old thing", 13)

Tests/test_features.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,6 @@ def test(name: str, function: Callable[[str], str | None]) -> None:
5555
test(feature, features.version_feature)
5656

5757

58-
def test_webp_transparency() -> None:
59-
with pytest.warns(DeprecationWarning, match="transp_webp"):
60-
assert (features.check("transp_webp") or False) == features.check_module("webp")
61-
62-
63-
def test_webp_mux() -> None:
64-
with pytest.warns(DeprecationWarning, match="webp_mux"):
65-
assert (features.check("webp_mux") or False) == features.check_module("webp")
66-
67-
68-
def test_webp_anim() -> None:
69-
with pytest.warns(DeprecationWarning, match="webp_anim"):
70-
assert (features.check("webp_anim") or False) == features.check_module("webp")
71-
72-
7358
@skip_unless_feature("libjpeg_turbo")
7459
def test_libjpeg_turbo_version() -> None:
7560
version = features.version("libjpeg_turbo")

Tests/test_file_icns.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,11 @@ def test_sizes() -> None:
9393
with Image.open(TEST_FILE) as im:
9494
assert isinstance(im, IcnsImagePlugin.IcnsImageFile)
9595
for w, h, r in im.info["sizes"]:
96-
wr = w * r
97-
hr = h * r
98-
with pytest.warns(
99-
DeprecationWarning, match=r"Setting size to \(width, height, scale\)"
100-
):
101-
im.size = (w, h, r)
102-
im.load()
103-
assert im.mode == "RGBA"
104-
assert im.size == (wr, hr)
105-
10696
# Test using load() with scale
10797
im.size = (w, h)
10898
im.load(scale=r)
10999
assert im.mode == "RGBA"
110-
assert im.size == (wr, hr)
100+
assert im.size == (w * r, h * r)
111101

112102
# Check that we cannot load an incorrect size
113103
with pytest.raises(ValueError):

Tests/test_file_iptc.py

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
from __future__ import annotations
22

3-
import sys
4-
from io import BytesIO, StringIO
5-
6-
import pytest
3+
from io import BytesIO
74

85
from PIL import Image, IptcImagePlugin, TiffImagePlugin, TiffTags
96

@@ -101,35 +98,3 @@ def test_getiptcinfo_tiff_none() -> None:
10198

10299
# Assert
103100
assert iptc is None
104-
105-
106-
def test_i() -> None:
107-
# Arrange
108-
c = b"a"
109-
110-
# Act
111-
with pytest.warns(DeprecationWarning, match="IptcImagePlugin.i"):
112-
ret = IptcImagePlugin.i(c)
113-
114-
# Assert
115-
assert ret == 97
116-
117-
118-
def test_dump(monkeypatch: pytest.MonkeyPatch) -> None:
119-
# Arrange
120-
c = b"abc"
121-
# Temporarily redirect stdout
122-
mystdout = StringIO()
123-
monkeypatch.setattr(sys, "stdout", mystdout)
124-
125-
# Act
126-
with pytest.warns(DeprecationWarning, match="IptcImagePlugin.dump"):
127-
IptcImagePlugin.dump(c)
128-
129-
# Assert
130-
assert mystdout.getvalue() == "61 62 63 \n"
131-
132-
133-
def test_pad_deprecation() -> None:
134-
with pytest.warns(DeprecationWarning, match="IptcImagePlugin.PAD"):
135-
assert IptcImagePlugin.PAD == b"\0\0\0\0"

Tests/test_file_jpeg.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,14 +1115,6 @@ def test_repr_jpeg_error_returns_none(self) -> None:
11151115

11161116
assert im._repr_jpeg_() is None
11171117

1118-
def test_deprecation(self) -> None:
1119-
with Image.open(TEST_FILE) as im:
1120-
assert isinstance(im, JpegImagePlugin.JpegImageFile)
1121-
with pytest.warns(DeprecationWarning, match="huffman_ac"):
1122-
assert im.huffman_ac == {}
1123-
with pytest.warns(DeprecationWarning, match="huffman_dc"):
1124-
assert im.huffman_dc == {}
1125-
11261118

11271119
@pytest.mark.skipif(not is_win32(), reason="Windows only")
11281120
@skip_unless_feature("jpg")

Tests/test_file_libtiff.py

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -256,19 +256,7 @@ def test_additional_metadata(
256256

257257
im.save(out, tiffinfo=new_ifd)
258258

259-
@pytest.mark.parametrize(
260-
"libtiff",
261-
(
262-
pytest.param(
263-
True,
264-
marks=pytest.mark.skipif(
265-
not getattr(Image.core, "libtiff_support_custom_tags", False),
266-
reason="Custom tags not supported by older libtiff",
267-
),
268-
),
269-
False,
270-
),
271-
)
259+
@pytest.mark.parametrize("libtiff", (True, False))
272260
def test_custom_metadata(
273261
self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path, libtiff: bool
274262
) -> None:
@@ -724,8 +712,7 @@ def test_exif_ifd(self) -> None:
724712

725713
with Image.open(out) as reloaded:
726714
assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
727-
if Image.core.libtiff_support_custom_tags:
728-
assert reloaded.tag_v2[34665] == 125456
715+
assert reloaded.tag_v2[34665] == 125456
729716

730717
def test_crashing_metadata(
731718
self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
@@ -777,19 +764,7 @@ def test_read_icc(self, monkeypatch: pytest.MonkeyPatch) -> None:
777764
assert icc_libtiff is not None
778765
assert icc == icc_libtiff
779766

780-
@pytest.mark.parametrize(
781-
"libtiff",
782-
(
783-
pytest.param(
784-
True,
785-
marks=pytest.mark.skipif(
786-
not getattr(Image.core, "libtiff_support_custom_tags", False),
787-
reason="Custom tags not supported by older libtiff",
788-
),
789-
),
790-
False,
791-
),
792-
)
767+
@pytest.mark.parametrize("libtiff", (True, False))
793768
def test_write_icc(
794769
self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path, libtiff: bool
795770
) -> None:

Tests/test_image.py

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
assert_image_similar_tofile,
3131
assert_not_all_same,
3232
hopper,
33-
is_big_endian,
3433
is_win32,
3534
mark_if_feature_version,
3635
skip_unless_feature,
@@ -50,19 +49,10 @@
5049
PrettyPrinter = None
5150

5251

53-
# Deprecation helper
54-
def helper_image_new(mode: str, size: tuple[int, int]) -> Image.Image:
55-
if mode.startswith("BGR;"):
56-
with pytest.warns(DeprecationWarning, match="BGR;"):
57-
return Image.new(mode, size)
58-
else:
59-
return Image.new(mode, size)
60-
61-
6252
class TestImage:
63-
@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
53+
@pytest.mark.parametrize("mode", Image.MODES)
6454
def test_image_modes_success(self, mode: str) -> None:
65-
helper_image_new(mode, (1, 1))
55+
Image.new(mode, (1, 1))
6656

6757
@pytest.mark.parametrize("mode", ("", "bad", "very very long"))
6858
def test_image_modes_fail(self, mode: str) -> None:
@@ -1142,39 +1132,29 @@ def test_close_graceful(self, caplog: pytest.LogCaptureFixture) -> None:
11421132
assert len(caplog.records) == 0
11431133
assert im.fp is None
11441134

1145-
def test_deprecation(self) -> None:
1146-
with pytest.warns(DeprecationWarning, match="Image.isImageType"):
1147-
assert not Image.isImageType(None)
1148-
11491135

11501136
class TestImageBytes:
1151-
@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
1137+
@pytest.mark.parametrize("mode", Image.MODES)
11521138
def test_roundtrip_bytes_constructor(self, mode: str) -> None:
11531139
im = hopper(mode)
11541140
source_bytes = im.tobytes()
11551141

1156-
if mode.startswith("BGR;"):
1157-
with pytest.warns(DeprecationWarning, match=mode):
1158-
reloaded = Image.frombytes(mode, im.size, source_bytes)
1159-
else:
1160-
reloaded = Image.frombytes(mode, im.size, source_bytes)
1142+
reloaded = Image.frombytes(mode, im.size, source_bytes)
11611143
assert reloaded.tobytes() == source_bytes
11621144

1163-
@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
1145+
@pytest.mark.parametrize("mode", Image.MODES)
11641146
def test_roundtrip_bytes_method(self, mode: str) -> None:
11651147
im = hopper(mode)
11661148
source_bytes = im.tobytes()
11671149

1168-
reloaded = helper_image_new(mode, im.size)
1150+
reloaded = Image.new(mode, im.size)
11691151
reloaded.frombytes(source_bytes)
11701152
assert reloaded.tobytes() == source_bytes
11711153

1172-
@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
1154+
@pytest.mark.parametrize("mode", Image.MODES)
11731155
def test_getdata_putdata(self, mode: str) -> None:
1174-
if is_big_endian() and mode == "BGR;15":
1175-
pytest.xfail("Known failure of BGR;15 on big-endian")
11761156
im = hopper(mode)
1177-
reloaded = helper_image_new(mode, im.size)
1157+
reloaded = Image.new(mode, im.size)
11781158
reloaded.putdata(im.getdata())
11791159
assert_image_equal(im, reloaded)
11801160

Tests/test_image_access.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ def color(mode: str) -> int | tuple[int, ...]:
123123
bands = Image.getmodebands(mode)
124124
if bands == 1:
125125
return 1
126-
if mode in ("BGR;15", "BGR;16"):
127-
# These modes have less than 8 bits per band,
128-
# so (1, 2, 3) cannot be roundtripped.
129-
return (16, 32, 49)
130126
return tuple(range(1, bands + 1))
131127

132128
def check(self, mode: str, expected_color_int: int | None = None) -> None:
@@ -191,11 +187,6 @@ def check(self, mode: str, expected_color_int: int | None = None) -> None:
191187
def test_basic(self, mode: str) -> None:
192188
self.check(mode)
193189

194-
@pytest.mark.parametrize("mode", ("BGR;15", "BGR;16", "BGR;24"))
195-
def test_deprecated(self, mode: str) -> None:
196-
with pytest.warns(DeprecationWarning, match="BGR;"):
197-
self.check(mode)
198-
199190
def test_list(self) -> None:
200191
im = hopper()
201192
assert im.getpixel([0, 0]) == (20, 20, 70)
@@ -218,7 +209,7 @@ def test_p_putpixel_rgb_rgba(self, mode: str, color: tuple[int, ...]) -> None:
218209

219210

220211
class TestImagePutPixelError:
221-
IMAGE_MODES1 = ["LA", "RGB", "RGBA", "BGR;15"]
212+
IMAGE_MODES1 = ["LA", "RGB", "RGBA"]
222213
IMAGE_MODES2 = ["L", "I", "I;16"]
223214
INVALID_TYPES = ["foo", 1.0, None]
224215

@@ -234,11 +225,6 @@ def test_putpixel_type_error1(self, mode: str) -> None:
234225
(
235226
("L", (0, 2), "color must be int or single-element tuple"),
236227
("LA", (0, 3), "color must be int, or tuple of one or two elements"),
237-
(
238-
"BGR;15",
239-
(0, 2),
240-
"color must be int, or tuple of one or three elements",
241-
),
242228
(
243229
"RGB",
244230
(0, 2, 5),

Tests/test_image_getim.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
import pytest
4-
53
from .helper import hopper
64

75

@@ -10,10 +8,3 @@ def test_sanity() -> None:
108

119
type_repr = repr(type(im.getim()))
1210
assert "PyCapsule" in type_repr
13-
14-
with pytest.warns(DeprecationWarning, match="id property"):
15-
assert isinstance(im.im.id, int)
16-
17-
with pytest.warns(DeprecationWarning, match="unsafe_ptrs property"):
18-
ptrs = dict(im.im.unsafe_ptrs)
19-
assert ptrs.keys() == {"image8", "image32", "image"}

0 commit comments

Comments
 (0)