Skip to content

Commit ba9ac5b

Browse files
Issue #16261: Converted some bare except statements to except statements
with specified exception type. Original patch by Ramchandra Apte.
1 parent 492f027 commit ba9ac5b

File tree

7 files changed

+13
-13
lines changed

7 files changed

+13
-13
lines changed

Lib/functools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from weakref import WeakKeyDictionary
2424
try:
2525
from _thread import RLock
26-
except:
26+
except ImportError:
2727
class RLock:
2828
'Dummy reentrant lock for builds without threads'
2929
def __enter__(self): pass

Lib/ipaddress.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def v4_int_to_packed(address):
135135
"""
136136
try:
137137
return address.to_bytes(4, 'big')
138-
except:
138+
except OverflowError:
139139
raise ValueError("Address negative or too large for IPv4")
140140

141141

@@ -151,7 +151,7 @@ def v6_int_to_packed(address):
151151
"""
152152
try:
153153
return address.to_bytes(16, 'big')
154-
except:
154+
except OverflowError:
155155
raise ValueError("Address negative or too large for IPv6")
156156

157157

Lib/uuid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def _netbios_getnode():
465465
for libname in ['uuid', 'c']:
466466
try:
467467
lib = ctypes.CDLL(ctypes.util.find_library(libname))
468-
except:
468+
except Exception:
469469
continue
470470
if hasattr(lib, 'uuid_generate_random'):
471471
_uuid_generate_random = lib.uuid_generate_random
@@ -607,7 +607,7 @@ def uuid4():
607607
try:
608608
import os
609609
return UUID(bytes=os.urandom(16), version=4)
610-
except:
610+
except Exception:
611611
import random
612612
return UUID(int=random.getrandbits(128), version=4)
613613

Mac/BuildScript/build-installer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ def getTclTkVersion(configfile, versionline):
572572
"""
573573
try:
574574
f = open(configfile, "r")
575-
except:
575+
except OSError:
576576
fatal("Framework configuration file not found: %s" % configfile)
577577

578578
for l in f:
@@ -814,7 +814,7 @@ def downloadURL(url, fname):
814814
except:
815815
try:
816816
os.unlink(fname)
817-
except:
817+
except OSError:
818818
pass
819819

820820
def verifyThirdPartyFile(url, checksum, fname):

Tools/demo/ss1.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,21 +261,21 @@ def start_value(self, attrs):
261261
def end_int(self, text):
262262
try:
263263
self.value = int(text)
264-
except:
264+
except (TypeError, ValueError):
265265
self.value = None
266266

267267
end_long = end_int
268268

269269
def end_double(self, text):
270270
try:
271271
self.value = float(text)
272-
except:
272+
except (TypeError, ValueError):
273273
self.value = None
274274

275275
def end_complex(self, text):
276276
try:
277277
self.value = complex(text)
278-
except:
278+
except (TypeError, ValueError):
279279
self.value = None
280280

281281
def end_string(self, text):
@@ -763,7 +763,7 @@ def change_cell(self):
763763
for cls in int, float, complex:
764764
try:
765765
value = cls(text)
766-
except:
766+
except (TypeError, ValueError):
767767
continue
768768
else:
769769
cell = NumericCell(value)

Tools/scripts/eptags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def treat_file(filename, outfp):
2525
"""Append tags found in file named 'filename' to the open file 'outfp'"""
2626
try:
2727
fp = open(filename, 'r')
28-
except:
28+
except OSError:
2929
sys.stderr.write('Cannot open %s\n'%filename)
3030
return
3131
charno = 0

Tools/unicode/gencodec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def hexrepr(t, precision=4):
127127
return 'None'
128128
try:
129129
len(t)
130-
except:
130+
except TypeError:
131131
return '0x%0*X' % (precision, t)
132132
try:
133133
return '(' + ', '.join(['0x%0*X' % (precision, item)

0 commit comments

Comments
 (0)