From afb7dce5e24130cef36665de6e40baebbb5dbb36 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 8 Dec 2019 16:24:17 +0100 Subject: [PATCH] Suppress exception chaining on rc validator failure. This changes the traceback from Traceback (most recent call last): File ".../matplotlib/__init__.py", line 768, in __setitem__ cval = self.validate[key](val) File ".../matplotlib/rcsetup.py", line 67, in __call__ raise ValueError('Unrecognized %s string %r: valid strings are %s' ValueError: Unrecognized capstyle string 'foobar': valid strings are ['butt', 'round', 'projecting'] During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 4, in File ".../matplotlib/__init__.py", line 770, in __setitem__ raise ValueError("Key %s: %s" % (key, str(ve))) ValueError: Key lines.solid_capstyle: Unrecognized capstyle string 'foobar': valid strings are ['butt', 'round', 'projecting'] to Traceback (most recent call last): File "", line 4, in File ".../matplotlib/__init__.py", line 770, in __setitem__ raise ValueError(f"Key {key}: {ve}") from None ValueError: Key lines.solid_capstyle: Unrecognized capstyle string 'foobar': valid strings are ['butt', 'round', 'projecting'] --- lib/matplotlib/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 623173a23d6e..27ce53b8e18e 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -767,7 +767,7 @@ def __setitem__(self, key, val): try: cval = self.validate[key](val) except ValueError as ve: - raise ValueError("Key %s: %s" % (key, str(ve))) + raise ValueError(f"Key {key}: {ve}") from None dict.__setitem__(self, key, cval) except KeyError: raise KeyError(