Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e80b658

Browse files
Issue #27238: Got rid of bare excepts in the turtle module. Original patch
by Jelle Zijlstra.
2 parents 319a57c + cefa917 commit e80b658

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

Lib/turtle.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def config_dict(filename):
179179
continue
180180
try:
181181
key, value = line.split("=")
182-
except:
182+
except ValueError:
183183
print("Bad line in config-file %s:\n%s" % (filename,line))
184184
continue
185185
key = key.strip()
@@ -192,7 +192,7 @@ def config_dict(filename):
192192
value = float(value)
193193
else:
194194
value = int(value)
195-
except:
195+
except ValueError:
196196
pass # value need not be converted
197197
cfgdict[key] = value
198198
return cfgdict
@@ -220,7 +220,7 @@ def readconfig(cfgdict):
220220
try:
221221
head, tail = split(__file__)
222222
cfg_file2 = join(head, default_cfg)
223-
except:
223+
except Exception:
224224
cfg_file2 = ""
225225
if isfile(cfg_file2):
226226
cfgdict2 = config_dict(cfg_file2)
@@ -229,7 +229,7 @@ def readconfig(cfgdict):
229229

230230
try:
231231
readconfig(_CFG)
232-
except:
232+
except Exception:
233233
print ("No configfile read, reason unknown")
234234

235235

@@ -653,7 +653,7 @@ def eventfun(event):
653653
x, y = (self.cv.canvasx(event.x)/self.xscale,
654654
-self.cv.canvasy(event.y)/self.yscale)
655655
fun(x, y)
656-
except:
656+
except Exception:
657657
pass
658658
self.cv.tag_bind(item, "<Button%s-Motion>" % num, eventfun, add)
659659

@@ -1158,7 +1158,7 @@ def _colorstr(self, color):
11581158
raise TurtleGraphicsError("bad color string: %s" % str(color))
11591159
try:
11601160
r, g, b = color
1161-
except:
1161+
except (TypeError, ValueError):
11621162
raise TurtleGraphicsError("bad color arguments: %s" % str(color))
11631163
if self._colormode == 1.0:
11641164
r, g, b = [round(255.0*x) for x in (r, g, b)]
@@ -2702,7 +2702,7 @@ def _cc(self, args):
27022702
return args
27032703
try:
27042704
r, g, b = args
2705-
except:
2705+
except (TypeError, ValueError):
27062706
raise TurtleGraphicsError("bad color arguments: %s" % str(args))
27072707
if self.screen._colormode == 1.0:
27082708
r, g, b = [round(255.0*x) for x in (r, g, b)]
@@ -3865,7 +3865,7 @@ def read_docstrings(lang):
38653865
try:
38663866
# eval(key).im_func.__doc__ = docsdict[key]
38673867
eval(key).__doc__ = docsdict[key]
3868-
except:
3868+
except Exception:
38693869
print("Bad docstring-entry: %s" % key)
38703870

38713871
_LANGUAGE = _CFG["language"]
@@ -3875,7 +3875,7 @@ def read_docstrings(lang):
38753875
read_docstrings(_LANGUAGE)
38763876
except ImportError:
38773877
print("Cannot find docsdict for", _LANGUAGE)
3878-
except:
3878+
except Exception:
38793879
print ("Unknown Error when trying to import %s-docstring-dictionary" %
38803880
_LANGUAGE)
38813881

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.6.0 alpha 3
1010
Library
1111
-------
1212

13+
- Issue #27238: Got rid of bare excepts in the turtle module. Original patch
14+
by Jelle Zijlstra.
15+
1316
- Issue #27122: When an exception is raised within the context being managed
1417
by a contextlib.ExitStack() and one of the exit stack generators
1518
catches and raises it in a chain, do not re-raise the original exception

0 commit comments

Comments
 (0)