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

Skip to content

Commit d52382b

Browse files
committed
Fix exception causes in rcsetup.py
1 parent 9a24fb7 commit d52382b

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

lib/matplotlib/rcsetup.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ def _validate_tex_preamble(s):
171171
return '\n'.join(s)
172172
else:
173173
raise TypeError
174-
except TypeError:
175-
raise ValueError('Could not convert "%s" to string' % s)
174+
except TypeError as e:
175+
raise ValueError('Could not convert "%s" to string' % s) from e
176176

177177

178178
def validate_axisbelow(s):
@@ -193,9 +193,9 @@ def validate_dpi(s):
193193
return s
194194
try:
195195
return float(s)
196-
except ValueError:
196+
except ValueError as e:
197197
raise ValueError(f'{s!r} is not string "figure" and '
198-
f'could not convert {s!r} to float')
198+
f'could not convert {s!r} to float') from e
199199

200200

201201
def _make_type_validator(cls, *, allow_none=False):
@@ -210,8 +210,8 @@ def validator(s):
210210
return None
211211
try:
212212
return cls(s)
213-
except ValueError:
214-
raise ValueError(f'Could not convert {s!r} to {cls.__name__}')
213+
except ValueError as e:
214+
raise ValueError(f'Could not convert {s!r} to {cls.__name__}') from e
215215

216216
validator.__name__ = f"validate_{cls.__name__}"
217217
if allow_none:
@@ -245,9 +245,9 @@ def validate_fonttype(s):
245245
except ValueError:
246246
try:
247247
return fonttypes[s.lower()]
248-
except KeyError:
248+
except KeyError as e:
249249
raise ValueError(
250-
'Supported Postscript/PDF font types are %s' % list(fonttypes))
250+
'Supported Postscript/PDF font types are %s' % list(fonttypes)) from e
251251
else:
252252
if fonttype not in fonttypes.values():
253253
raise ValueError(
@@ -291,9 +291,9 @@ def validator(s):
291291
try:
292292
return [cls(val) if not allow_none or val is not None else val
293293
for val in s]
294-
except ValueError:
294+
except ValueError as e:
295295
raise ValueError(
296-
f'Could not convert all entries to {cls.__name__}s')
296+
f'Could not convert all entries to {cls.__name__}s') from e
297297

298298
return validator
299299

@@ -367,8 +367,8 @@ def validate_aspect(s):
367367
return s
368368
try:
369369
return float(s)
370-
except ValueError:
371-
raise ValueError('not a valid aspect specification')
370+
except ValueError as e:
371+
raise ValueError('not a valid aspect specification') from e
372372

373373

374374
def validate_fontsize_None(s):
@@ -387,9 +387,9 @@ def validate_fontsize(s):
387387
return s
388388
try:
389389
return float(s)
390-
except ValueError:
390+
except ValueError as e:
391391
raise ValueError("%s is not a valid font size. Valid font sizes "
392-
"are %s." % (s, ", ".join(fontsizes)))
392+
"are %s." % (s, ", ".join(fontsizes))) from e
393393

394394

395395
validate_fontsizelist = _listify_validator(validate_fontsize)
@@ -404,8 +404,8 @@ def validate_fontweight(s):
404404
return s
405405
try:
406406
return int(s)
407-
except (ValueError, TypeError):
408-
raise ValueError(f'{s} is not a valid font weight.')
407+
except (ValueError, TypeError) as e:
408+
raise ValueError(f'{s} is not a valid font weight.') from e
409409

410410

411411
def validate_font_properties(s):
@@ -441,9 +441,9 @@ def validate_whiskers(s):
441441
try:
442442
v = float(s)
443443
return v
444-
except ValueError:
444+
except ValueError as e:
445445
raise ValueError("Not a valid whisker value ['range', float, "
446-
"(float, float)]")
446+
"(float, float)]") from e
447447

448448

449449
@cbook.deprecated("3.2")
@@ -897,7 +897,7 @@ def validate_cycler(s):
897897
s = eval(s, {'cycler': cycler, '__builtins__': {}})
898898
except BaseException as e:
899899
raise ValueError("'%s' is not a valid cycler construction: %s" %
900-
(s, e))
900+
(s, e)) from e
901901
# Should make sure what comes from the above eval()
902902
# is a Cycler object.
903903
if isinstance(s, Cycler):
@@ -975,8 +975,8 @@ def validate_webagg_address(s):
975975
import socket
976976
try:
977977
socket.inet_aton(s)
978-
except socket.error:
979-
raise ValueError("'webagg.address' is not a valid IP address")
978+
except socket.error as e:
979+
raise ValueError("'webagg.address' is not a valid IP address") from e
980980
return s
981981
raise ValueError("'webagg.address' is not a valid IP address")
982982

0 commit comments

Comments
 (0)