[Python-checkins] cpython: Issue #16261: Converted some bare except statements to except statements
serhiy.storchaka
python-checkins at python.org
Wed May 20 09:34:05 CEST 2015
https://hg.python.org/cpython/rev/b3a7215b9ce4
changeset: 96166:b3a7215b9ce4
user: Serhiy Storchaka <storchaka at gmail.com>
date: Wed May 20 10:33:40 2015 +0300
summary:
Issue #16261: Converted some bare except statements to except statements
with specified exception type. Original patch by Ramchandra Apte.
files:
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
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -23,7 +23,7 @@
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
--- a/Lib/ipaddress.py
+++ b/Lib/ipaddress.py
@@ -135,7 +135,7 @@
"""
try:
return address.to_bytes(4, 'big')
- except:
+ except OverflowError:
raise ValueError("Address negative or too large for IPv4")
@@ -151,7 +151,7 @@
"""
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
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -465,7 +465,7 @@
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 @@
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
--- a/Mac/BuildScript/build-installer.py
+++ b/Mac/BuildScript/build-installer.py
@@ -572,7 +572,7 @@
"""
try:
f = open(configfile, "r")
- except:
+ except OSError:
fatal("Framework configuration file not found: %s" % configfile)
for l in f:
@@ -814,7 +814,7 @@
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
--- a/Tools/demo/ss1.py
+++ b/Tools/demo/ss1.py
@@ -261,7 +261,7 @@
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 @@
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 @@
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
--- a/Tools/scripts/eptags.py
+++ b/Tools/scripts/eptags.py
@@ -25,7 +25,7 @@
"""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
--- a/Tools/unicode/gencodec.py
+++ b/Tools/unicode/gencodec.py
@@ -127,7 +127,7 @@
return 'None'
try:
len(t)
- except:
+ except TypeError:
return '0x%0*X' % (precision, t)
try:
return '(' + ', '.join(['0x%0*X' % (precision, item)
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list