From ba9ac5b5c42a9bba54942211a3b00a1c3ce7bb23 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 20 May 2015 10:33:40 +0300 Subject: Issue #16261: Converted some bare except statements to except statements with specified exception type. Original patch by Ramchandra Apte. --- Lib/functools.py | 2 +- Lib/ipaddress.py | 4 ++-- Lib/uuid.py | 4 ++-- Mac/BuildScript/build-installer.py | 4 ++-- Tools/demo/ss1.py | 8 ++++---- Tools/scripts/eptags.py | 2 +- Tools/unicode/gencodec.py | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Lib/functools.py b/Lib/functools.py index fb2e4bd..19c25e1 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -23,7 +23,7 @@ from types import MappingProxyType from weakref import WeakKeyDictionary try: from _thread import RLock -except: +except ImportError: class RLock: 'Dummy reentrant lock for builds without threads' def __enter__(self): pass diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index be1ec52..7469a9d 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -135,7 +135,7 @@ def v4_int_to_packed(address): """ try: return address.to_bytes(4, 'big') - except: + except OverflowError: raise ValueError("Address negative or too large for IPv4") @@ -151,7 +151,7 @@ def v6_int_to_packed(address): """ try: return address.to_bytes(16, 'big') - except: + except OverflowError: raise ValueError("Address negative or too large for IPv6") diff --git a/Lib/uuid.py b/Lib/uuid.py index e627573..5c731ec 100644 --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -465,7 +465,7 @@ try: for libname in ['uuid', 'c']: try: lib = ctypes.CDLL(ctypes.util.find_library(libname)) - except: + except Exception: continue if hasattr(lib, 'uuid_generate_random'): _uuid_generate_random = lib.uuid_generate_random @@ -607,7 +607,7 @@ def uuid4(): try: import os return UUID(bytes=os.urandom(16), version=4) - except: + except Exception: import random return UUID(int=random.getrandbits(128), version=4) diff --git a/Mac/BuildScript/build-installer.py b/Mac/BuildScript/build-installer.py index 8728289..47cbe3d 100755 --- a/Mac/BuildScript/build-installer.py +++ b/Mac/BuildScript/build-installer.py @@ -572,7 +572,7 @@ def getTclTkVersion(configfile, versionline): """ try: f = open(configfile, "r") - except: + except OSError: fatal("Framework configuration file not found: %s" % configfile) for l in f: @@ -814,7 +814,7 @@ def downloadURL(url, fname): except: try: os.unlink(fname) - except: + except OSError: pass def verifyThirdPartyFile(url, checksum, fname): diff --git a/Tools/demo/ss1.py b/Tools/demo/ss1.py index 649790f..c51f041 100755 --- a/Tools/demo/ss1.py +++ b/Tools/demo/ss1.py @@ -261,7 +261,7 @@ class SheetParser: def end_int(self, text): try: self.value = int(text) - except: + except (TypeError, ValueError): self.value = None end_long = end_int @@ -269,13 +269,13 @@ class SheetParser: def end_double(self, text): try: self.value = float(text) - except: + except (TypeError, ValueError): self.value = None def end_complex(self, text): try: self.value = complex(text) - except: + except (TypeError, ValueError): self.value = None def end_string(self, text): @@ -763,7 +763,7 @@ class SheetGUI: for cls in int, float, complex: try: value = cls(text) - except: + except (TypeError, ValueError): continue else: cell = NumericCell(value) diff --git a/Tools/scripts/eptags.py b/Tools/scripts/eptags.py index 671ff11..401ac7e 100755 --- a/Tools/scripts/eptags.py +++ b/Tools/scripts/eptags.py @@ -25,7 +25,7 @@ def treat_file(filename, outfp): """Append tags found in file named 'filename' to the open file 'outfp'""" try: fp = open(filename, 'r') - except: + except OSError: sys.stderr.write('Cannot open %s\n'%filename) return charno = 0 diff --git a/Tools/unicode/gencodec.py b/Tools/unicode/gencodec.py index 98b3975..4c21469 100644 --- a/Tools/unicode/gencodec.py +++ b/Tools/unicode/gencodec.py @@ -127,7 +127,7 @@ def hexrepr(t, precision=4): return 'None' try: len(t) - except: + except TypeError: return '0x%0*X' % (precision, t) try: return '(' + ', '.join(['0x%0*X' % (precision, item) -- cgit v0.12