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

Skip to content

Commit 878c8c4

Browse files
authored
Merge pull request #16609 from cool-RR/2020-02-28-raise-from
Fix exception causes in rcsetup.py
2 parents 619ad3c + d52382b commit 878c8c4

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):
@@ -199,9 +199,9 @@ def validate_dpi(s):
199199
return s
200200
try:
201201
return float(s)
202-
except ValueError:
202+
except ValueError as e:
203203
raise ValueError(f'{s!r} is not string "figure" and '
204-
f'could not convert {s!r} to float')
204+
f'could not convert {s!r} to float') from e
205205

206206

207207
def _make_type_validator(cls, *, allow_none=False):
@@ -216,8 +216,8 @@ def validator(s):
216216
return None
217217
try:
218218
return cls(s)
219-
except ValueError:
220-
raise ValueError(f'Could not convert {s!r} to {cls.__name__}')
219+
except ValueError as e:
220+
raise ValueError(f'Could not convert {s!r} to {cls.__name__}') from e
221221

222222
validator.__name__ = f"validate_{cls.__name__}"
223223
if allow_none:
@@ -251,9 +251,9 @@ def validate_fonttype(s):
251251
except ValueError:
252252
try:
253253
return fonttypes[s.lower()]
254-
except KeyError:
254+
except KeyError as e:
255255
raise ValueError(
256-
'Supported Postscript/PDF font types are %s' % list(fonttypes))
256+
'Supported Postscript/PDF font types are %s' % list(fonttypes)) from e
257257
else:
258258
if fonttype not in fonttypes.values():
259259
raise ValueError(
@@ -297,9 +297,9 @@ def validator(s):
297297
try:
298298
return [cls(val) if not allow_none or val is not None else val
299299
for val in s]
300-
except ValueError:
300+
except ValueError as e:
301301
raise ValueError(
302-
f'Could not convert all entries to {cls.__name__}s')
302+
f'Could not convert all entries to {cls.__name__}s') from e
303303

304304
return validator
305305

@@ -373,8 +373,8 @@ def validate_aspect(s):
373373
return s
374374
try:
375375
return float(s)
376-
except ValueError:
377-
raise ValueError('not a valid aspect specification')
376+
except ValueError as e:
377+
raise ValueError('not a valid aspect specification') from e
378378

379379

380380
def validate_fontsize_None(s):
@@ -393,9 +393,9 @@ def validate_fontsize(s):
393393
return s
394394
try:
395395
return float(s)
396-
except ValueError:
396+
except ValueError as e:
397397
raise ValueError("%s is not a valid font size. Valid font sizes "
398-
"are %s." % (s, ", ".join(fontsizes)))
398+
"are %s." % (s, ", ".join(fontsizes))) from e
399399

400400

401401
validate_fontsizelist = _listify_validator(validate_fontsize)
@@ -410,8 +410,8 @@ def validate_fontweight(s):
410410
return s
411411
try:
412412
return int(s)
413-
except (ValueError, TypeError):
414-
raise ValueError(f'{s} is not a valid font weight.')
413+
except (ValueError, TypeError) as e:
414+
raise ValueError(f'{s} is not a valid font weight.') from e
415415

416416

417417
def validate_font_properties(s):
@@ -447,9 +447,9 @@ def validate_whiskers(s):
447447
try:
448448
v = float(s)
449449
return v
450-
except ValueError:
450+
except ValueError as e:
451451
raise ValueError("Not a valid whisker value ['range', float, "
452-
"(float, float)]")
452+
"(float, float)]") from e
453453

454454

455455
@cbook.deprecated("3.2")
@@ -903,7 +903,7 @@ def validate_cycler(s):
903903
s = eval(s, {'cycler': cycler, '__builtins__': {}})
904904
except BaseException as e:
905905
raise ValueError("'%s' is not a valid cycler construction: %s" %
906-
(s, e))
906+
(s, e)) from e
907907
# Should make sure what comes from the above eval()
908908
# is a Cycler object.
909909
if isinstance(s, Cycler):
@@ -981,8 +981,8 @@ def validate_webagg_address(s):
981981
import socket
982982
try:
983983
socket.inet_aton(s)
984-
except socket.error:
985-
raise ValueError("'webagg.address' is not a valid IP address")
984+
except socket.error as e:
985+
raise ValueError("'webagg.address' is not a valid IP address") from e
986986
return s
987987
raise ValueError("'webagg.address' is not a valid IP address")
988988

0 commit comments

Comments
 (0)