@@ -229,7 +229,9 @@ def test_load_transparent_p(self) -> None:
229
229
assert_image (im , "RGBA" , (162 , 150 ))
230
230
231
231
# image has 124 unique alpha values
232
- assert len (im .getchannel ("A" ).getcolors ()) == 124
232
+ colors = im .getchannel ("A" ).getcolors ()
233
+ assert colors is not None
234
+ assert len (colors ) == 124
233
235
234
236
def test_load_transparent_rgb (self ) -> None :
235
237
test_file = "Tests/images/rgb_trns.png"
@@ -241,7 +243,9 @@ def test_load_transparent_rgb(self) -> None:
241
243
assert_image (im , "RGBA" , (64 , 64 ))
242
244
243
245
# image has 876 transparent pixels
244
- assert im .getchannel ("A" ).getcolors ()[0 ][0 ] == 876
246
+ colors = im .getchannel ("A" ).getcolors ()
247
+ assert colors is not None
248
+ assert colors [0 ][0 ] == 876
245
249
246
250
def test_save_p_transparent_palette (self , tmp_path : Path ) -> None :
247
251
in_file = "Tests/images/pil123p.png"
@@ -262,7 +266,9 @@ def test_save_p_transparent_palette(self, tmp_path: Path) -> None:
262
266
assert_image (im , "RGBA" , (162 , 150 ))
263
267
264
268
# image has 124 unique alpha values
265
- assert len (im .getchannel ("A" ).getcolors ()) == 124
269
+ colors = im .getchannel ("A" ).getcolors ()
270
+ assert colors is not None
271
+ assert len (colors ) == 124
266
272
267
273
def test_save_p_single_transparency (self , tmp_path : Path ) -> None :
268
274
in_file = "Tests/images/p_trns_single.png"
@@ -285,7 +291,9 @@ def test_save_p_single_transparency(self, tmp_path: Path) -> None:
285
291
assert im .getpixel ((31 , 31 )) == (0 , 255 , 52 , 0 )
286
292
287
293
# image has 876 transparent pixels
288
- assert im .getchannel ("A" ).getcolors ()[0 ][0 ] == 876
294
+ colors = im .getchannel ("A" ).getcolors ()
295
+ assert colors is not None
296
+ assert colors [0 ][0 ] == 876
289
297
290
298
def test_save_p_transparent_black (self , tmp_path : Path ) -> None :
291
299
# check if solid black image with full transparency
@@ -313,7 +321,9 @@ def test_save_grayscale_transparency(self, tmp_path: Path) -> None:
313
321
assert im .info ["transparency" ] == 255
314
322
315
323
im_rgba = im .convert ("RGBA" )
316
- assert im_rgba .getchannel ("A" ).getcolors ()[0 ][0 ] == num_transparent
324
+ colors = im_rgba .getchannel ("A" ).getcolors ()
325
+ assert colors is not None
326
+ assert colors [0 ][0 ] == num_transparent
317
327
318
328
test_file = tmp_path / "temp.png"
319
329
im .save (test_file )
@@ -324,7 +334,9 @@ def test_save_grayscale_transparency(self, tmp_path: Path) -> None:
324
334
assert_image_equal (im , test_im )
325
335
326
336
test_im_rgba = test_im .convert ("RGBA" )
327
- assert test_im_rgba .getchannel ("A" ).getcolors ()[0 ][0 ] == num_transparent
337
+ colors = test_im_rgba .getchannel ("A" ).getcolors ()
338
+ assert colors is not None
339
+ assert colors [0 ][0 ] == num_transparent
328
340
329
341
def test_save_rgb_single_transparency (self , tmp_path : Path ) -> None :
330
342
in_file = "Tests/images/caption_6_33_22.png"
0 commit comments