Skip to content

Commit da70ca2

Browse files
committed
Fix exception causes in 19 modules
1 parent 9a24fb7 commit da70ca2

File tree

19 files changed

+51
-51
lines changed

19 files changed

+51
-51
lines changed

lib/matplotlib/markers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ def set_marker(self, marker):
287287
try:
288288
Path(marker)
289289
self._marker_function = self._set_vertices
290-
except ValueError:
290+
except ValueError as err:
291291
raise ValueError('Unrecognized marker style {!r}'
292-
.format(marker))
292+
.format(marker)) from err
293293

294294
self._marker = marker
295295
self._recache()

lib/matplotlib/mathtext.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ def get_unicode_index(symbol, math=True):
7373
pass
7474
try: # Is symbol a TeX symbol (i.e. \alpha)
7575
return tex2uni[symbol.strip("\\")]
76-
except KeyError:
76+
except KeyError as err:
7777
raise ValueError(
7878
"'{}' is not a valid Unicode character or TeX/Type1 symbol"
79-
.format(symbol))
79+
.format(symbol)) from err
8080

8181

8282
class MathtextBackend:
@@ -2582,7 +2582,7 @@ def parse(self, s, fonts_object, fontsize, dpi):
25822582
raise ValueError("\n".join(["",
25832583
err.line,
25842584
" " * (err.column - 1) + "^",
2585-
str(err)]))
2585+
str(err)])) from err
25862586
self._state_stack = None
25872587
self._em_width_cache = {}
25882588
self._expression.resetCache()
@@ -2697,8 +2697,8 @@ def symbol(self, s, loc, toks):
26972697
c = toks[0]
26982698
try:
26992699
char = Char(c, self.get_state())
2700-
except ValueError:
2701-
raise ParseFatalException(s, loc, "Unknown symbol: %s" % c)
2700+
except ValueError as err:
2701+
raise ParseFatalException(s, loc, "Unknown symbol: %s" % c) from err
27022702

27032703
if c in self._spaced_symbols:
27042704
# iterate until we find previous character, needed for cases

lib/matplotlib/offsetbox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,8 +1167,8 @@ def set_bbox_to_anchor(self, bbox, transform=None):
11671167
else:
11681168
try:
11691169
l = len(bbox)
1170-
except TypeError:
1171-
raise ValueError("Invalid argument for bbox : %s" % str(bbox))
1170+
except TypeError as err:
1171+
raise ValueError("Invalid argument for bbox : %s" % str(bbox)) from err
11721172

11731173
if l == 2:
11741174
bbox = [bbox[0], bbox[1], 0, 0]

lib/matplotlib/patches.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,14 +1844,14 @@ def __new__(cls, stylename, **kw):
18441844
_name = _list[0].lower()
18451845
try:
18461846
_cls = cls._style_list[_name]
1847-
except KeyError:
1848-
raise ValueError("Unknown style : %s" % stylename)
1847+
except KeyError as err:
1848+
raise ValueError("Unknown style : %s" % stylename) from err
18491849

18501850
try:
18511851
_args_pair = [cs.split("=") for cs in _list[1:]]
18521852
_args = {k: float(v) for k, v in _args_pair}
1853-
except ValueError:
1854-
raise ValueError("Incorrect style argument : %s" % stylename)
1853+
except ValueError as err:
1854+
raise ValueError("Incorrect style argument : %s" % stylename) from err
18551855
_args.update(kw)
18561856

18571857
return _cls(**_args)

lib/matplotlib/projections/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def get_projection_class(projection=None):
5252

5353
try:
5454
return projection_registry.get_projection_class(projection)
55-
except KeyError:
56-
raise ValueError("Unknown projection %r" % projection)
55+
except KeyError as err:
56+
raise ValueError("Unknown projection %r" % projection) from err
5757

5858

5959
get_projection_names = projection_registry.get_projection_names

lib/matplotlib/pyplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ def uninstall_repl_displayhook():
155155
ip = get_ipython()
156156
try:
157157
ip.events.unregister('post_execute', _IP_REGISTERED)
158-
except AttributeError:
158+
except AttributeError as err:
159159
raise NotImplementedError("Can not unregister events "
160-
"in IPython < 2.0")
160+
"in IPython < 2.0") from err
161161
_IP_REGISTERED = None
162162

163163
if _INSTALL_FIG_OBSERVER:

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,11 @@ def run_code(code, code_path, ns=None, function_name=None):
444444
except OSError as err:
445445
raise OSError(str(err) + '\n`plot_working_directory` option in'
446446
'Sphinx configuration file must be a valid '
447-
'directory path')
447+
'directory path') from err
448448
except TypeError as err:
449449
raise TypeError(str(err) + '\n`plot_working_directory` option in '
450450
'Sphinx configuration file must be a string or '
451-
'None')
451+
'None') from err
452452
elif code_path is not None:
453453
dirname = os.path.abspath(os.path.dirname(code_path))
454454
os.chdir(dirname)
@@ -475,8 +475,8 @@ def run_code(code, code_path, ns=None, function_name=None):
475475
if function_name is not None:
476476
exec(function_name + "()", ns)
477477

478-
except (Exception, SystemExit):
479-
raise PlotError(traceback.format_exc())
478+
except (Exception, SystemExit) as err:
479+
raise PlotError(traceback.format_exc()) from err
480480
finally:
481481
os.chdir(pwd)
482482
return ns
@@ -600,8 +600,8 @@ def render_figures(code, code_path, output_dir, output_base, context,
600600
for fmt, dpi in formats:
601601
try:
602602
figman.canvas.figure.savefig(img.filename(fmt), dpi=dpi)
603-
except Exception:
604-
raise PlotError(traceback.format_exc())
603+
except Exception as err:
604+
raise PlotError(traceback.format_exc()) from err
605605
img.formats.append(fmt)
606606

607607
results.append((code_piece, images))

lib/matplotlib/streamplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ class StreamMask:
372372
def __init__(self, density):
373373
try:
374374
self.nx, self.ny = (30 * np.broadcast_to(density, 2)).astype(int)
375-
except ValueError:
376-
raise ValueError("'density' must be a scalar or be of length 2")
375+
except ValueError as err:
376+
raise ValueError("'density' must be a scalar or be of length 2") from err
377377
if self.nx < 0 or self.ny < 0:
378378
raise ValueError("'density' must be positive")
379379
self._mask = np.zeros((self.ny, self.nx))

lib/matplotlib/style/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ def use(style):
114114
try:
115115
rc = rc_params_from_file(style, use_default_template=False)
116116
_apply_style(rc)
117-
except IOError:
117+
except IOError as err:
118118
raise IOError(
119119
"{!r} not found in the style library and input is not a "
120120
"valid URL or path; see `style.available` for list of "
121-
"available styles".format(style))
121+
"available styles".format(style)) from err
122122

123123

124124
@contextlib.contextmanager

lib/matplotlib/table.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ def __setitem__(self, position, cell):
358358
cbook._check_isinstance(CustomCell, cell=cell)
359359
try:
360360
row, col = position[0], position[1]
361-
except Exception:
362-
raise KeyError('Only tuples length 2 are accepted as coordinates')
361+
except Exception as err:
362+
raise KeyError('Only tuples length 2 are accepted as coordinates') from err
363363
cell.set_figure(self.figure)
364364
cell.set_transform(self.get_transform())
365365
cell.set_clip_on(False)

0 commit comments

Comments
 (0)