mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-05-02 15:03:42 +03:00
Updated type hints
This commit is contained in:
parent
c252b708ee
commit
5ff20273d9
|
@ -685,22 +685,33 @@ class ImageFileDirectory_v2(_IFDv2Base):
|
||||||
else:
|
else:
|
||||||
self.tagtype[tag] = TiffTags.UNDEFINED
|
self.tagtype[tag] = TiffTags.UNDEFINED
|
||||||
if all(isinstance(v, IFDRational) for v in values):
|
if all(isinstance(v, IFDRational) for v in values):
|
||||||
self.tagtype[tag] = (
|
for v in values:
|
||||||
TiffTags.RATIONAL
|
assert isinstance(v, IFDRational)
|
||||||
if all(v >= 0 for v in values)
|
if v < 0:
|
||||||
else TiffTags.SIGNED_RATIONAL
|
self.tagtype[tag] = TiffTags.SIGNED_RATIONAL
|
||||||
)
|
break
|
||||||
elif all(isinstance(v, int) for v in values):
|
|
||||||
if all(0 <= v < 2**16 for v in values):
|
|
||||||
self.tagtype[tag] = TiffTags.SHORT
|
|
||||||
elif all(-(2**15) < v < 2**15 for v in values):
|
|
||||||
self.tagtype[tag] = TiffTags.SIGNED_SHORT
|
|
||||||
else:
|
else:
|
||||||
self.tagtype[tag] = (
|
self.tagtype[tag] = TiffTags.RATIONAL
|
||||||
TiffTags.LONG
|
elif all(isinstance(v, int) for v in values):
|
||||||
if all(v >= 0 for v in values)
|
short = True
|
||||||
else TiffTags.SIGNED_LONG
|
signed_short = True
|
||||||
)
|
long = True
|
||||||
|
for v in values:
|
||||||
|
assert isinstance(v, int)
|
||||||
|
if short and not (0 <= v < 2**16):
|
||||||
|
short = False
|
||||||
|
if signed_short and not (-(2**15) < v < 2**15):
|
||||||
|
signed_short = False
|
||||||
|
if long and v < 0:
|
||||||
|
long = False
|
||||||
|
if short:
|
||||||
|
self.tagtype[tag] = TiffTags.SHORT
|
||||||
|
elif signed_short:
|
||||||
|
self.tagtype[tag] = TiffTags.SIGNED_SHORT
|
||||||
|
elif long:
|
||||||
|
self.tagtype[tag] = TiffTags.LONG
|
||||||
|
else:
|
||||||
|
self.tagtype[tag] = TiffTags.SIGNED_LONG
|
||||||
elif all(isinstance(v, float) for v in values):
|
elif all(isinstance(v, float) for v in values):
|
||||||
self.tagtype[tag] = TiffTags.DOUBLE
|
self.tagtype[tag] = TiffTags.DOUBLE
|
||||||
elif all(isinstance(v, str) for v in values):
|
elif all(isinstance(v, str) for v in values):
|
||||||
|
@ -718,7 +729,10 @@ class ImageFileDirectory_v2(_IFDv2Base):
|
||||||
|
|
||||||
is_ifd = self.tagtype[tag] == TiffTags.LONG and isinstance(values, dict)
|
is_ifd = self.tagtype[tag] == TiffTags.LONG and isinstance(values, dict)
|
||||||
if not is_ifd:
|
if not is_ifd:
|
||||||
values = tuple(info.cvt_enum(value) for value in values)
|
values = tuple(
|
||||||
|
info.cvt_enum(value) if isinstance(value, str) else value
|
||||||
|
for value in values
|
||||||
|
)
|
||||||
|
|
||||||
dest = self._tags_v1 if legacy_api else self._tags_v2
|
dest = self._tags_v1 if legacy_api else self._tags_v2
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user