diff --git a/PIL/GifImagePlugin.py b/PIL/GifImagePlugin.py index bdda5c185..7fe662fc6 100644 --- a/PIL/GifImagePlugin.py +++ b/PIL/GifImagePlugin.py @@ -415,10 +415,7 @@ def _save(im, fp, filename, save_all=False): def get_interlace(im): - try: - interlace = im.encoderinfo["interlace"] - except KeyError: - interlace = 1 + interlace = im.encoderinfo.get("interlace", 1) # workaround for @PIL153 if min(im.size) < 16: @@ -484,10 +481,7 @@ def _get_local_header(fp, im, offset, flags): o8(0)) include_color_table = im.encoderinfo.get('include_color_table') if include_color_table: - try: - palette = im.encoderinfo["palette"] - except KeyError: - palette = None + palette = im.encoderinfo.get("palette", None) palette_bytes = _get_palette_bytes(im, palette, im.encoderinfo)[0] color_table_size = _get_color_table_size(palette_bytes) if color_table_size: diff --git a/PIL/ImImagePlugin.py b/PIL/ImImagePlugin.py index 4638419fa..b0edac409 100644 --- a/PIL/ImImagePlugin.py +++ b/PIL/ImImagePlugin.py @@ -325,10 +325,7 @@ def _save(im, fp, filename, check=0): except KeyError: raise ValueError("Cannot save %s images as IM" % im.mode) - try: - frames = im.encoderinfo["frames"] - except KeyError: - frames = 1 + frames = im.encoderinfo.get("frames", 1) if check: return check diff --git a/PIL/Image.py b/PIL/Image.py index 77f2836c0..a656209e5 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -2194,10 +2194,7 @@ def fromarray(obj, mode=None): arr = obj.__array_interface__ shape = arr['shape'] ndim = len(shape) - try: - strides = arr['strides'] - except KeyError: - strides = None + strides = arr.get('strides', None) if mode is None: try: typekey = (1, 1) + shape[2:], arr['typestr'] diff --git a/Scripts/player.py b/Scripts/player.py index ac9eb817f..40873ff5f 100644 --- a/Scripts/player.py +++ b/Scripts/player.py @@ -38,10 +38,7 @@ class UI(Label): self.update() - try: - duration = im.info["duration"] - except KeyError: - duration = 100 + duration = im.info.get("duration", 100) self.after(duration, self.next) def next(self): @@ -64,10 +61,7 @@ class UI(Label): except EOFError: return # end of file - try: - duration = im.info["duration"] - except KeyError: - duration = 100 + duration = im.info.get("duration", 100) self.after(duration, self.next) self.update_idletasks()