@@ -220,7 +220,7 @@ class Quantize(IntEnum):
220220if TYPE_CHECKING :
221221 from xml .etree .ElementTree import Element
222222
223- from . import ImageFile , ImagePalette
223+ from . import ImageFile , ImagePalette , TiffImagePlugin
224224 from ._typing import NumpyArray , StrOrBytesPath , TypeGuard
225225ID : list [str ] = []
226226OPEN : dict [
@@ -676,7 +676,7 @@ def __repr__(self) -> str:
676676 id (self ),
677677 )
678678
679- def _repr_pretty_ (self , p , cycle ) -> None :
679+ def _repr_pretty_ (self , p , cycle : bool ) -> None :
680680 """IPython plain text display support"""
681681
682682 # Same as __repr__ but without unpredictable id(self),
@@ -1551,6 +1551,7 @@ def get_child_images(self) -> list[ImageFile.ImageFile]:
15511551 ifds .append ((exif ._get_ifd_dict (subifd_offset ), subifd_offset ))
15521552 ifd1 = exif .get_ifd (ExifTags .IFD .IFD1 )
15531553 if ifd1 and ifd1 .get (513 ):
1554+ assert exif ._info is not None
15541555 ifds .append ((ifd1 , exif ._info .next ))
15551556
15561557 offset = None
@@ -1560,12 +1561,13 @@ def get_child_images(self) -> list[ImageFile.ImageFile]:
15601561 offset = current_offset
15611562
15621563 fp = self .fp
1563- thumbnail_offset = ifd .get (513 )
1564- if thumbnail_offset is not None :
1565- thumbnail_offset += getattr (self , "_exif_offset" , 0 )
1566- self .fp .seek (thumbnail_offset )
1567- data = self .fp .read (ifd .get (514 ))
1568- fp = io .BytesIO (data )
1564+ if ifd is not None :
1565+ thumbnail_offset = ifd .get (513 )
1566+ if thumbnail_offset is not None :
1567+ thumbnail_offset += getattr (self , "_exif_offset" , 0 )
1568+ self .fp .seek (thumbnail_offset )
1569+ data = self .fp .read (ifd .get (514 ))
1570+ fp = io .BytesIO (data )
15691571
15701572 with open (fp ) as im :
15711573 from . import TiffImagePlugin
@@ -3869,39 +3871,41 @@ class Exif(_ExifBase):
38693871 bigtiff = False
38703872 _loaded = False
38713873
3872- def __init__ (self ):
3873- self ._data = {}
3874- self ._hidden_data = {}
3875- self ._ifds = {}
3876- self ._info = None
3877- self ._loaded_exif = None
3874+ def __init__ (self ) -> None :
3875+ self ._data : dict [ int , Any ] = {}
3876+ self ._hidden_data : dict [ int , Any ] = {}
3877+ self ._ifds : dict [ int , dict [ int , Any ]] = {}
3878+ self ._info : TiffImagePlugin . ImageFileDirectory_v2 | None = None
3879+ self ._loaded_exif : bytes | None = None
38783880
3879- def _fixup (self , value ) :
3881+ def _fixup (self , value : Any ) -> Any :
38803882 try :
38813883 if len (value ) == 1 and isinstance (value , tuple ):
38823884 return value [0 ]
38833885 except Exception :
38843886 pass
38853887 return value
38863888
3887- def _fixup_dict (self , src_dict ) :
3889+ def _fixup_dict (self , src_dict : dict [ int , Any ]) -> dict [ int , Any ] :
38883890 # Helper function
38893891 # returns a dict with any single item tuples/lists as individual values
38903892 return {k : self ._fixup (v ) for k , v in src_dict .items ()}
38913893
3892- def _get_ifd_dict (self , offset : int , group : int | None = None ):
3894+ def _get_ifd_dict (
3895+ self , offset : int , group : int | None = None
3896+ ) -> dict [int , Any ] | None :
38933897 try :
38943898 # an offset pointer to the location of the nested embedded IFD.
38953899 # It should be a long, but may be corrupted.
38963900 self .fp .seek (offset )
38973901 except (KeyError , TypeError ):
3898- pass
3902+ return None
38993903 else :
39003904 from . import TiffImagePlugin
39013905
39023906 info = TiffImagePlugin .ImageFileDirectory_v2 (self .head , group = group )
39033907 info .load (self .fp )
3904- return self ._fixup_dict (info )
3908+ return self ._fixup_dict (dict ( info ) )
39053909
39063910 def _get_head (self ) -> bytes :
39073911 version = b"\x2B " if self .bigtiff else b"\x2A "
@@ -3966,7 +3970,7 @@ def load_from_fp(self, fp: IO[bytes], offset: int | None = None) -> None:
39663970 self .fp .seek (offset )
39673971 self ._info .load (self .fp )
39683972
3969- def _get_merged_dict (self ):
3973+ def _get_merged_dict (self ) -> dict [ int , Any ] :
39703974 merged_dict = dict (self )
39713975
39723976 # get EXIF extension
@@ -4124,7 +4128,7 @@ def __len__(self) -> int:
41244128 keys .update (self ._info )
41254129 return len (keys )
41264130
4127- def __getitem__ (self , tag : int ):
4131+ def __getitem__ (self , tag : int ) -> Any :
41284132 if self ._info is not None and tag not in self ._data and tag in self ._info :
41294133 self ._data [tag ] = self ._fixup (self ._info [tag ])
41304134 del self ._info [tag ]
@@ -4133,7 +4137,7 @@ def __getitem__(self, tag: int):
41334137 def __contains__ (self , tag : object ) -> bool :
41344138 return tag in self ._data or (self ._info is not None and tag in self ._info )
41354139
4136- def __setitem__ (self , tag : int , value ) -> None :
4140+ def __setitem__ (self , tag : int , value : Any ) -> None :
41374141 if self ._info is not None and tag in self ._info :
41384142 del self ._info [tag ]
41394143 self ._data [tag ] = value
0 commit comments