From c353225851e17fa1326a90b36c7fa6aa6907cbd8 Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 16 Nov 2018 23:51:52 +0200 Subject: [PATCH] Prefer 'except Exception:' to bare 'except:' --- Tests/helper.py | 4 ++-- mp_compile.py | 2 +- src/PIL/Image.py | 6 +++--- src/PIL/ImageFont.py | 2 +- src/PIL/ImageTk.py | 4 ++-- src/PIL/Jpeg2KImagePlugin.py | 6 +++--- src/PIL/JpegImagePlugin.py | 8 ++++---- src/PIL/PngImagePlugin.py | 2 +- src/PIL/PyAccess.py | 2 +- src/PIL/SpiderImagePlugin.py | 2 +- src/PIL/TiffImagePlugin.py | 2 +- winbuild/build.py | 2 +- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Tests/helper.py b/Tests/helper.py index f6995e4b5..c16798dca 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -84,7 +84,7 @@ class PillowTestCase(unittest.TestCase): self.assertTrue( all(x == y for x, y in zip(a, b)), msg or "got %s, expected %s" % (a, b)) - except: + except Exception: self.assertEqual(a, b, msg) def assert_image(self, im, mode, size, msg=None): @@ -149,7 +149,7 @@ class PillowTestCase(unittest.TestCase): try: url = test_image_results.upload(a, b) logger.error("Url for test images: %s" % url) - except: + except Exception: pass raise e diff --git a/mp_compile.py b/mp_compile.py index 9043e24b8..2d5287d77 100644 --- a/mp_compile.py +++ b/mp_compile.py @@ -43,7 +43,7 @@ def _mp_compile(self, sources, output_dir=None, macros=None, pool = Pool(MAX_PROCS) try: print("Building using %d processes" % pool._processes) - except: + except Exception: pass arr = [(self, obj, build, cc_args, extra_postargs, pp_opts) for obj in objects] diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 541c62c49..55c99dd3b 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -971,7 +971,7 @@ class Image(object): if isinstance(t, tuple): try: t = trns_im.palette.getcolor(t) - except: + except Exception: raise ValueError("Couldn't allocate a palette " "color for transparency") trns_im.putpixel((0, 0), t) @@ -1008,7 +1008,7 @@ class Image(object): if trns is not None: try: new.info['transparency'] = new.palette.getcolor(trns) - except: + except Exception: # if we can't make a transparent color, don't leave the old # transparency hanging around to mess us up. del(new.info['transparency']) @@ -1038,7 +1038,7 @@ class Image(object): if new_im.mode == 'P': try: new_im.info['transparency'] = new_im.palette.getcolor(trns) - except: + except Exception: del(new_im.info['transparency']) warnings.warn("Couldn't allocate palette entry " + "for transparency") diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index 227294925..7454b4413 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -72,7 +72,7 @@ class ImageFont(object): try: fullname = os.path.splitext(filename)[0] + ext image = Image.open(fullname) - except: + except Exception: pass else: if image and image.mode in ("1", "L"): diff --git a/src/PIL/ImageTk.py b/src/PIL/ImageTk.py index 935f9f778..cc0c5294c 100644 --- a/src/PIL/ImageTk.py +++ b/src/PIL/ImageTk.py @@ -124,7 +124,7 @@ class PhotoImage(object): self.__photo.name = None try: self.__photo.tk.call("image", "delete", name) - except: + except Exception: pass # ignore internal errors def __str__(self): @@ -244,7 +244,7 @@ class BitmapImage(object): self.__photo.name = None try: self.__photo.tk.call("image", "delete", name) - except: + except Exception: pass # ignore internal errors def width(self): diff --git a/src/PIL/Jpeg2KImagePlugin.py b/src/PIL/Jpeg2KImagePlugin.py index 2bf519896..172162c9a 100644 --- a/src/PIL/Jpeg2KImagePlugin.py +++ b/src/PIL/Jpeg2KImagePlugin.py @@ -181,14 +181,14 @@ class Jpeg2KImageFile(ImageFile.ImageFile): try: fd = self.fp.fileno() length = os.fstat(fd).st_size - except: + except Exception: fd = -1 try: pos = self.fp.tell() self.fp.seek(0, 2) length = self.fp.tell() self.fp.seek(pos, 0) - except: + except Exception: length = -1 self.tile = [('jpeg2k', (0, 0) + self.size, 0, @@ -250,7 +250,7 @@ def _save(im, fp, filename): if hasattr(fp, "fileno"): try: fd = fp.fileno() - except: + except Exception: fd = -1 im.encoderconfig = ( diff --git a/src/PIL/JpegImagePlugin.py b/src/PIL/JpegImagePlugin.py index 6090d252f..e43bdea6b 100644 --- a/src/PIL/JpegImagePlugin.py +++ b/src/PIL/JpegImagePlugin.py @@ -75,7 +75,7 @@ def APP(self, marker): try: jfif_unit = i8(s[7]) jfif_density = i16(s, 8), i16(s, 10) - except: + except Exception: pass else: if jfif_unit == 1: @@ -107,7 +107,7 @@ def APP(self, marker): # extract Adobe custom properties try: adobe_transform = i8(s[1]) - except: + except Exception: pass else: self.info["adobe_transform"] = adobe_transform @@ -441,7 +441,7 @@ def _fixup_dict(src_dict): try: if len(value) == 1 and not isinstance(value, dict): return value[0] - except: + except Exception: pass return value @@ -512,7 +512,7 @@ def _getmp(self): info = TiffImagePlugin.ImageFileDirectory_v2(head) info.load(file_contents) mp = dict(info) - except: + except Exception: raise SyntaxError("malformed MP Index (unreadable directory)") # it's an error not to have a number of images try: diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py index 15077fceb..7bfbcd37c 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -340,7 +340,7 @@ class PngStream(ChunkStream): self.im_size = i32(s), i32(s[4:]) try: self.im_mode, self.im_rawmode = _MODES[(i8(s[8]), i8(s[9]))] - except: + except Exception: pass if i8(s[12]): self.im_info["interlace"] = 1 diff --git a/src/PIL/PyAccess.py b/src/PIL/PyAccess.py index adbd6132d..c8278ea54 100644 --- a/src/PIL/PyAccess.py +++ b/src/PIL/PyAccess.py @@ -231,7 +231,7 @@ class _PyAccessI16_B(PyAccess): pixel = self.pixels[y][x] try: color = min(color, 65535) - except: + except Exception: color = min(color[0], 65535) pixel.l = color >> 8 diff --git a/src/PIL/SpiderImagePlugin.py b/src/PIL/SpiderImagePlugin.py index 3f5795210..96958b494 100644 --- a/src/PIL/SpiderImagePlugin.py +++ b/src/PIL/SpiderImagePlugin.py @@ -210,7 +210,7 @@ def loadImageSeries(filelist=None): continue try: im = Image.open(img).convert2byte() - except: + except Exception: if not isSpiderImage(img): print(img + " is not a Spider image file") continue diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index 30d5e620e..dfa47e02b 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -1413,7 +1413,7 @@ def _save(im, fp, filename): ifd[key] = info.get(key) try: ifd.tagtype[key] = info.tagtype[key] - except: + except Exception: pass # might not be an IFD, Might not have populated type # additions written by Greg Couch, gregc@cgl.ucsf.edu diff --git a/winbuild/build.py b/winbuild/build.py index 86c7f818b..313a14ff4 100755 --- a/winbuild/build.py +++ b/winbuild/build.py @@ -119,7 +119,7 @@ endlocal def clean(): try: shutil.rmtree('../build') - except: + except Exception: # could already be removed pass run_script(('virtualenvs', setup_vms()))