@@ -354,16 +354,16 @@ def test_palette_handling(tmp_path: Path) -> None:
354354 # see https://github.com/python-pillow/Pillow/issues/513
355355
356356 with Image .open (TEST_GIF ) as im :
357- im = im .convert ("RGB" )
357+ im_rgb = im .convert ("RGB" )
358358
359- im = im .resize ((100 , 100 ), Image .Resampling .LANCZOS )
360- im2 = im .convert ("P" , palette = Image .Palette .ADAPTIVE , colors = 256 )
359+ im_rgb = im_rgb .resize ((100 , 100 ), Image .Resampling .LANCZOS )
360+ im_p = im_rgb .convert ("P" , palette = Image .Palette .ADAPTIVE , colors = 256 )
361361
362- f = tmp_path / "temp.gif"
363- im2 .save (f , optimize = True )
362+ f = tmp_path / "temp.gif"
363+ im_p .save (f , optimize = True )
364364
365365 with Image .open (f ) as reloaded :
366- assert_image_similar (im , reloaded .convert ("RGB" ), 10 )
366+ assert_image_similar (im_rgb , reloaded .convert ("RGB" ), 10 )
367367
368368
369369def test_palette_434 (tmp_path : Path ) -> None :
@@ -383,35 +383,36 @@ def roundtrip(im: Image.Image, **kwargs: bool) -> Image.Image:
383383 with roundtrip (im , optimize = True ) as reloaded :
384384 assert_image_similar (im , reloaded , 1 )
385385
386- im = im .convert ("RGB" )
387- # check automatic P conversion
388- with roundtrip (im ) as reloaded :
389- reloaded = reloaded .convert ("RGB" )
390- assert_image_equal (im , reloaded )
386+ im_rgb = im .convert ("RGB" )
387+
388+ # check automatic P conversion
389+ with roundtrip (im_rgb ) as reloaded :
390+ reloaded = reloaded .convert ("RGB" )
391+ assert_image_equal (im_rgb , reloaded )
391392
392393
393394@pytest .mark .skipif (not netpbm_available (), reason = "Netpbm not available" )
394395def test_save_netpbm_bmp_mode (tmp_path : Path ) -> None :
395396 with Image .open (TEST_GIF ) as img :
396- img = img .convert ("RGB" )
397+ img_rgb = img .convert ("RGB" )
397398
398- tempfile = str (tmp_path / "temp.gif" )
399- b = BytesIO ()
400- GifImagePlugin ._save_netpbm (img , b , tempfile )
401- with Image .open (tempfile ) as reloaded :
402- assert_image_similar (img , reloaded .convert ("RGB" ), 0 )
399+ tempfile = str (tmp_path / "temp.gif" )
400+ b = BytesIO ()
401+ GifImagePlugin ._save_netpbm (img_rgb , b , tempfile )
402+ with Image .open (tempfile ) as reloaded :
403+ assert_image_similar (img_rgb , reloaded .convert ("RGB" ), 0 )
403404
404405
405406@pytest .mark .skipif (not netpbm_available (), reason = "Netpbm not available" )
406407def test_save_netpbm_l_mode (tmp_path : Path ) -> None :
407408 with Image .open (TEST_GIF ) as img :
408- img = img .convert ("L" )
409+ img_l = img .convert ("L" )
409410
410411 tempfile = str (tmp_path / "temp.gif" )
411412 b = BytesIO ()
412- GifImagePlugin ._save_netpbm (img , b , tempfile )
413+ GifImagePlugin ._save_netpbm (img_l , b , tempfile )
413414 with Image .open (tempfile ) as reloaded :
414- assert_image_similar (img , reloaded .convert ("L" ), 0 )
415+ assert_image_similar (img_l , reloaded .convert ("L" ), 0 )
415416
416417
417418def test_seek () -> None :
@@ -1038,26 +1039,26 @@ def test_webp_background(tmp_path: Path) -> None:
10381039 im .save (out )
10391040
10401041 # Test non-opaque WebP background
1041- im = Image .new ("L" , (100 , 100 ), "#000" )
1042- im .info ["background" ] = (0 , 0 , 0 , 0 )
1043- im .save (out )
1042+ im2 = Image .new ("L" , (100 , 100 ), "#000" )
1043+ im2 .info ["background" ] = (0 , 0 , 0 , 0 )
1044+ im2 .save (out )
10441045
10451046
10461047def test_comment (tmp_path : Path ) -> None :
10471048 with Image .open (TEST_GIF ) as im :
10481049 assert im .info ["comment" ] == b"File written by Adobe Photoshop\xa8 4.0"
10491050
10501051 out = tmp_path / "temp.gif"
1051- im = Image .new ("L" , (100 , 100 ), "#000" )
1052- im .info ["comment" ] = b"Test comment text"
1053- im .save (out )
1052+ im2 = Image .new ("L" , (100 , 100 ), "#000" )
1053+ im2 .info ["comment" ] = b"Test comment text"
1054+ im2 .save (out )
10541055 with Image .open (out ) as reread :
1055- assert reread .info ["comment" ] == im .info ["comment" ]
1056+ assert reread .info ["comment" ] == im2 .info ["comment" ]
10561057
1057- im .info ["comment" ] = "Test comment text"
1058- im .save (out )
1058+ im2 .info ["comment" ] = "Test comment text"
1059+ im2 .save (out )
10591060 with Image .open (out ) as reread :
1060- assert reread .info ["comment" ] == im .info ["comment" ].encode ()
1061+ assert reread .info ["comment" ] == im2 .info ["comment" ].encode ()
10611062
10621063 # Test that GIF89a is used for comments
10631064 assert reread .info ["version" ] == b"GIF89a"
0 commit comments