Skip to content

Commit

Permalink
Prefer 'except Exception:' to bare 'except:'
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Nov 16, 2018
1 parent 6cd6c23 commit efb958f
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def assert_deep_equal(self, a, b, msg=None):
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):
Expand Down Expand Up @@ -149,7 +149,7 @@ def assert_image_similar(self, a, b, epsilon, msg=None):
try:
url = test_image_results.upload(a, b)
logger.error("Url for test images: %s" % url)
except:
except Exception:
pass
raise e

Expand Down
2 changes: 1 addition & 1 deletion mp_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ def convert_transparency(m, v):
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)
Expand Down Expand Up @@ -1008,7 +1008,7 @@ def convert_transparency(m, v):
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'])
Expand Down Expand Up @@ -1038,7 +1038,7 @@ def convert_transparency(m, v):
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")
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _load_pilfont(self, filename):
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"):
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/ImageTk.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def __del__(self):
self.__photo.name = None
try:
self.__photo.tk.call("image", "delete", name)
except:
except Exception:
pass # ignore internal errors

def __str__(self):
Expand Down Expand Up @@ -244,7 +244,7 @@ def __del__(self):
self.__photo.name = None
try:
self.__photo.tk.call("image", "delete", name)
except:
except Exception:
pass # ignore internal errors

def width(self):
Expand Down
6 changes: 3 additions & 3 deletions src/PIL/Jpeg2KImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ def _open(self):
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,
Expand Down Expand Up @@ -250,7 +250,7 @@ def _save(im, fp, filename):
if hasattr(fp, "fileno"):
try:
fd = fp.fileno()
except:
except Exception:
fd = -1

im.encoderconfig = (
Expand Down
8 changes: 4 additions & 4 deletions src/PIL/JpegImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -441,7 +441,7 @@ def _fixup(value):
try:
if len(value) == 1 and not isinstance(value, dict):
return value[0]
except:
except Exception:
pass
return value

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/PngImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def chunk_IHDR(self, pos, length):
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
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/PyAccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def set_pixel(self, x, y, color):
pixel = self.pixels[y][x]
try:
color = min(color, 65535)
except:
except Exception:
color = min(color[0], 65535)

pixel.l = color >> 8
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/SpiderImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion winbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def build_one(py_ver, compiler, bit):
def clean():
try:
shutil.rmtree('../build')
except:
except Exception:
# could already be removed
pass
run_script(('virtualenvs', setup_vms()))
Expand Down

0 comments on commit efb958f

Please sign in to comment.