@@ -229,7 +229,9 @@ def test_load_transparent_p(self) -> None:
229229 assert_image (im , "RGBA" , (162 , 150 ))
230230
231231 # 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
233235
234236 def test_load_transparent_rgb (self ) -> None :
235237 test_file = "Tests/images/rgb_trns.png"
@@ -241,7 +243,9 @@ def test_load_transparent_rgb(self) -> None:
241243 assert_image (im , "RGBA" , (64 , 64 ))
242244
243245 # 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
245249
246250 def test_save_p_transparent_palette (self , tmp_path : Path ) -> None :
247251 in_file = "Tests/images/pil123p.png"
@@ -262,7 +266,9 @@ def test_save_p_transparent_palette(self, tmp_path: Path) -> None:
262266 assert_image (im , "RGBA" , (162 , 150 ))
263267
264268 # 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
266272
267273 def test_save_p_single_transparency (self , tmp_path : Path ) -> None :
268274 in_file = "Tests/images/p_trns_single.png"
@@ -285,7 +291,9 @@ def test_save_p_single_transparency(self, tmp_path: Path) -> None:
285291 assert im .getpixel ((31 , 31 )) == (0 , 255 , 52 , 0 )
286292
287293 # 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
289297
290298 def test_save_p_transparent_black (self , tmp_path : Path ) -> None :
291299 # check if solid black image with full transparency
@@ -313,7 +321,9 @@ def test_save_grayscale_transparency(self, tmp_path: Path) -> None:
313321 assert im .info ["transparency" ] == 255
314322
315323 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
317327
318328 test_file = tmp_path / "temp.png"
319329 im .save (test_file )
@@ -324,7 +334,9 @@ def test_save_grayscale_transparency(self, tmp_path: Path) -> None:
324334 assert_image_equal (im , test_im )
325335
326336 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
328340
329341 def test_save_rgb_single_transparency (self , tmp_path : Path ) -> None :
330342 in_file = "Tests/images/caption_6_33_22.png"
0 commit comments