Skip to content

Commit 092e37a

Browse files
authored
Merge branch 'main' into bump-pre-commit
2 parents d1894dc + 1788ab7 commit 092e37a

10 files changed

+40
-25
lines changed

Tests/test_file_avif.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ def test_load_transparent_rgb(self) -> None:
254254
assert_image(im, "RGBA", (64, 64))
255255

256256
# image has 876 transparent pixels
257-
assert im.getchannel("A").getcolors()[0] == (876, 0)
257+
colors = im.getchannel("A").getcolors()
258+
assert colors is not None
259+
assert colors[0] == (876, 0)
258260

259261
def test_save_transparent(self, tmp_path: Path) -> None:
260262
im = Image.new("RGBA", (10, 10), (0, 0, 0, 0))

Tests/test_file_gif.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,9 @@ def test_dispose_background_transparency() -> None:
540540
img.seek(2)
541541
px = img.load()
542542
assert px is not None
543-
assert px[35, 30][3] == 0
543+
value = px[35, 30]
544+
assert isinstance(value, tuple)
545+
assert value[3] == 0
544546

545547

546548
@pytest.mark.parametrize(
@@ -1424,7 +1426,9 @@ def test_getdata(monkeypatch: pytest.MonkeyPatch) -> None:
14241426
def test_lzw_bits() -> None:
14251427
# see https://github.com/python-pillow/Pillow/issues/2811
14261428
with Image.open("Tests/images/issue_2811.gif") as im:
1427-
assert im.tile[0][3][0] == 11 # LZW bits
1429+
args = im.tile[0][3]
1430+
assert isinstance(args, tuple)
1431+
assert args[0] == 11 # LZW bits
14281432
# codec error prepatch
14291433
im.load()
14301434

@@ -1479,7 +1483,11 @@ def test_saving_rgba(tmp_path: Path) -> None:
14791483

14801484
with Image.open(out) as reloaded:
14811485
reloaded_rgba = reloaded.convert("RGBA")
1482-
assert reloaded_rgba.load()[0, 0][3] == 0
1486+
px = reloaded_rgba.load()
1487+
assert px is not None
1488+
value = px[0, 0]
1489+
assert isinstance(value, tuple)
1490+
assert value[3] == 0
14831491

14841492

14851493
@pytest.mark.parametrize("params", ({}, {"disposal": 2, "optimize": False}))

Tests/test_file_jpeg.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,33 +130,27 @@ def test_comment_write(self) -> None:
130130
def test_cmyk(self) -> None:
131131
# Test CMYK handling. Thanks to Tim and Charlie for test data,
132132
# Michael for getting me to look one more time.
133-
f = "Tests/images/pil_sample_cmyk.jpg"
134-
with Image.open(f) as im:
135-
# the source image has red pixels in the upper left corner.
136-
c, m, y, k = (x / 255.0 for x in im.getpixel((0, 0)))
137-
assert c == 0.0
138-
assert m > 0.8
139-
assert y > 0.8
140-
assert k == 0.0
141-
# the opposite corner is black
142-
c, m, y, k = (
143-
x / 255.0 for x in im.getpixel((im.size[0] - 1, im.size[1] - 1))
144-
)
145-
assert k > 0.9
146-
# roundtrip, and check again
147-
im = self.roundtrip(im)
133+
def check(im: ImageFile.ImageFile) -> None:
148134
cmyk = im.getpixel((0, 0))
149135
assert isinstance(cmyk, tuple)
150136
c, m, y, k = (x / 255.0 for x in cmyk)
151137
assert c == 0.0
152138
assert m > 0.8
153139
assert y > 0.8
154140
assert k == 0.0
141+
# the opposite corner is black
155142
cmyk = im.getpixel((im.size[0] - 1, im.size[1] - 1))
156143
assert isinstance(cmyk, tuple)
157144
k = cmyk[3] / 255.0
158145
assert k > 0.9
159146

147+
with Image.open("Tests/images/pil_sample_cmyk.jpg") as im:
148+
# the source image has red pixels in the upper left corner.
149+
check(im)
150+
151+
# roundtrip, and check again
152+
check(self.roundtrip(im))
153+
160154
def test_rgb(self) -> None:
161155
def getchannels(im: JpegImagePlugin.JpegImageFile) -> tuple[int, ...]:
162156
return tuple(v[0] for v in im.layer)

Tests/test_file_mpo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def test_reload_exif_after_seek() -> None:
156156
def test_mp(test_file: str) -> None:
157157
with Image.open(test_file) as im:
158158
mpinfo = im._getmp()
159+
assert mpinfo is not None
159160
assert mpinfo[45056] == b"0100"
160161
assert mpinfo[45057] == 2
161162

@@ -165,6 +166,7 @@ def test_mp_offset() -> None:
165166
# in APP2 data, in contrast to normal 8
166167
with Image.open("Tests/images/sugarshack_ifd_offset.mpo") as im:
167168
mpinfo = im._getmp()
169+
assert mpinfo is not None
168170
assert mpinfo[45056] == b"0100"
169171
assert mpinfo[45057] == 2
170172

@@ -181,6 +183,7 @@ def test_mp_no_data() -> None:
181183
def test_mp_attribute(test_file: str) -> None:
182184
with Image.open(test_file) as im:
183185
mpinfo = im._getmp()
186+
assert mpinfo is not None
184187
for frame_number, mpentry in enumerate(mpinfo[0xB002]):
185188
mpattr = mpentry["Attribute"]
186189
if frame_number:

Tests/test_file_tga.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,16 @@ def test_horizontal_orientations() -> None:
222222
with Image.open("Tests/images/rgb32rle_top_right.tga") as im:
223223
px = im.load()
224224
assert px is not None
225-
assert px[90, 90][:3] == (0, 0, 0)
225+
value = px[90, 90]
226+
assert isinstance(value, tuple)
227+
assert value[:3] == (0, 0, 0)
226228

227229
with Image.open("Tests/images/rgb32rle_bottom_right.tga") as im:
228230
px = im.load()
229231
assert px is not None
230-
assert px[90, 90][:3] == (0, 255, 0)
232+
value = px[90, 90]
233+
assert isinstance(value, tuple)
234+
assert value[:3] == (0, 255, 0)
231235

232236

233237
def test_save_rle(tmp_path: Path) -> None:

Tests/test_file_webp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ def test_background_from_gif(self, tmp_path: Path) -> None:
219219
# Save P mode GIF with background
220220
with Image.open("Tests/images/chi.gif") as im:
221221
original_value = im.convert("RGB").getpixel((1, 1))
222+
assert isinstance(original_value, tuple)
222223

223224
# Save as WEBP
224225
im.save(out_webp, save_all=True)
@@ -230,6 +231,7 @@ def test_background_from_gif(self, tmp_path: Path) -> None:
230231

231232
with Image.open(out_gif) as reread:
232233
reread_value = reread.convert("RGB").getpixel((1, 1))
234+
assert isinstance(reread_value, tuple)
233235
difference = sum(abs(original_value[i] - reread_value[i]) for i in range(3))
234236
assert difference < 5
235237

Tests/test_image_array.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Any
3+
from typing import Any
44

55
import pytest
66
from packaging.version import parse as parse_version
@@ -13,6 +13,7 @@
1313

1414
im = hopper().resize((128, 100))
1515

16+
TYPE_CHECKING = False
1617
if TYPE_CHECKING:
1718
import numpy.typing as npt
1819

Tests/test_numpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from __future__ import annotations
22

33
import warnings
4-
from typing import TYPE_CHECKING
54

65
import pytest
76

87
from PIL import Image, _typing
98

109
from .helper import assert_deep_equal, assert_image, hopper, skip_unless_feature
1110

11+
TYPE_CHECKING = False
1212
if TYPE_CHECKING:
1313
import numpy
1414
import numpy.typing as npt

Tests/test_qt_image_qapplication.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from __future__ import annotations
22

33
from pathlib import Path
4-
from typing import TYPE_CHECKING, Union
4+
from typing import Union
55

66
import pytest
77

88
from PIL import Image, ImageQt
99

1010
from .helper import assert_image_equal_tofile, assert_image_similar, hopper
1111

12+
TYPE_CHECKING = False
1213
if TYPE_CHECKING:
1314
import PyQt6
1415
import PySide6

docs/dater.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import re
1010
import subprocess
11-
from typing import TYPE_CHECKING
1211

12+
TYPE_CHECKING = False
1313
if TYPE_CHECKING:
1414
from sphinx.application import Sphinx
1515

0 commit comments

Comments
 (0)