Replaced hasattr conditions with getattr and default

This commit is contained in:
Andrew Murray 2019-03-18 09:15:37 +11:00
parent 22b0110f89
commit 9bdab56689
2 changed files with 3 additions and 7 deletions

View File

@ -578,8 +578,7 @@ class Image(object):
return self return self
def __exit__(self, *args): def __exit__(self, *args):
if (hasattr(self, 'fp') and hasattr(self, '_exclusive_fp') if hasattr(self, 'fp') and getattr(self, '_exclusive_fp', False):
and self._exclusive_fp):
if hasattr(self, "_close__fp"): if hasattr(self, "_close__fp"):
self._close__fp() self._close__fp()
if self.fp: if self.fp:

View File

@ -186,7 +186,7 @@ def _save_all(im, fp, filename):
# will preserve non-alpha modes # will preserve non-alpha modes
total = 0 total = 0
for ims in [im]+append_images: for ims in [im]+append_images:
total += 1 if not hasattr(ims, "n_frames") else ims.n_frames total += getattr(ims, "n_frames", 1)
if total == 1: if total == 1:
_save(im, fp, filename) _save(im, fp, filename)
return return
@ -254,10 +254,7 @@ def _save_all(im, fp, filename):
try: try:
for ims in [im]+append_images: for ims in [im]+append_images:
# Get # of frames in this image # Get # of frames in this image
if not hasattr(ims, "n_frames"): nfr = getattr(ims, "n_frames", 1)
nfr = 1
else:
nfr = ims.n_frames
for idx in range(nfr): for idx in range(nfr):
ims.seek(idx) ims.seek(idx)