@@ -334,8 +334,10 @@ def test_exif_gps(self, tmp_path: Path) -> None:
334334
335335 # Reading
336336 with Image .open ("Tests/images/exif_gps.jpg" ) as im :
337- exif = im ._getexif ()
338- assert exif [gps_index ] == expected_exif_gps
337+ assert isinstance (im , JpegImagePlugin .JpegImageFile )
338+ exif_data = im ._getexif ()
339+ assert exif_data is not None
340+ assert exif_data [gps_index ] == expected_exif_gps
339341
340342 # Writing
341343 f = tmp_path / "temp.jpg"
@@ -344,8 +346,10 @@ def test_exif_gps(self, tmp_path: Path) -> None:
344346 hopper ().save (f , exif = exif )
345347
346348 with Image .open (f ) as reloaded :
347- exif = reloaded ._getexif ()
348- assert exif [gps_index ] == expected_exif_gps
349+ assert isinstance (reloaded , JpegImagePlugin .JpegImageFile )
350+ exif_data = reloaded ._getexif ()
351+ assert exif_data is not None
352+ assert exif_data [gps_index ] == expected_exif_gps
349353
350354 def test_empty_exif_gps (self ) -> None :
351355 with Image .open ("Tests/images/empty_gps_ifd.jpg" ) as im :
@@ -372,6 +376,7 @@ def test_exif_equality(self) -> None:
372376 exifs = []
373377 for i in range (2 ):
374378 with Image .open ("Tests/images/exif-200dpcm.jpg" ) as im :
379+ assert isinstance (im , JpegImagePlugin .JpegImageFile )
375380 exifs .append (im ._getexif ())
376381 assert exifs [0 ] == exifs [1 ]
377382
@@ -405,13 +410,17 @@ def test_exif_rollback(self) -> None:
405410 }
406411
407412 with Image .open ("Tests/images/exif_gps.jpg" ) as im :
413+ assert isinstance (im , JpegImagePlugin .JpegImageFile )
408414 exif = im ._getexif ()
415+ assert exif is not None
409416
410417 for tag , value in expected_exif .items ():
411418 assert value == exif [tag ]
412419
413420 def test_exif_gps_typeerror (self ) -> None :
414421 with Image .open ("Tests/images/exif_gps_typeerror.jpg" ) as im :
422+ assert isinstance (im , JpegImagePlugin .JpegImageFile )
423+
415424 # Should not raise a TypeError
416425 im ._getexif ()
417426
@@ -491,7 +500,9 @@ def getsampling(
491500
492501 def test_exif (self ) -> None :
493502 with Image .open ("Tests/images/pil_sample_rgb.jpg" ) as im :
503+ assert isinstance (im , JpegImagePlugin .JpegImageFile )
494504 info = im ._getexif ()
505+ assert info is not None
495506 assert info [305 ] == "Adobe Photoshop CS Macintosh"
496507
497508 def test_get_child_images (self ) -> None :
@@ -676,11 +687,13 @@ def test_load_16bit_qtables(self) -> None:
676687
677688 def test_save_multiple_16bit_qtables (self ) -> None :
678689 with Image .open ("Tests/images/hopper_16bit_qtables.jpg" ) as im :
690+ assert isinstance (im , JpegImagePlugin .JpegImageFile )
679691 im2 = self .roundtrip (im , qtables = "keep" )
680692 assert im .quantization == im2 .quantization
681693
682694 def test_save_single_16bit_qtable (self ) -> None :
683695 with Image .open ("Tests/images/hopper_16bit_qtables.jpg" ) as im :
696+ assert isinstance (im , JpegImagePlugin .JpegImageFile )
684697 im2 = self .roundtrip (im , qtables = {0 : im .quantization [0 ]})
685698 assert len (im2 .quantization ) == 1
686699 assert im2 .quantization [0 ] == im .quantization [0 ]
@@ -889,7 +902,10 @@ def test_ifd_offset_exif(self) -> None:
889902 # in contrast to normal 8
890903 with Image .open ("Tests/images/exif-ifd-offset.jpg" ) as im :
891904 # Act / Assert
892- assert im ._getexif ()[306 ] == "2017:03:13 23:03:09"
905+ assert isinstance (im , JpegImagePlugin .JpegImageFile )
906+ exif = im ._getexif ()
907+ assert exif is not None
908+ assert exif [306 ] == "2017:03:13 23:03:09"
893909
894910 def test_multiple_exif (self ) -> None :
895911 with Image .open ("Tests/images/multiple_exif.jpg" ) as im :
0 commit comments