Skip to content

Commit 9c3eed4

Browse files
committed
Catch TypeError when validating rcParams types.
From a `matplotlibrc` point of view, the only input would be strings, which could raise `ValueError`. But from a code point of view, _anything_ could be assigned to `rcParams`. This raises a `TypeError` instead of the validator message.
1 parent 3b1be53 commit 9c3eed4

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def validator(s):
246246
return None
247247
try:
248248
return cls(s)
249-
except ValueError as e:
249+
except (TypeError, ValueError) as e:
250250
raise ValueError(
251251
f'Could not convert {s!r} to {cls.__name__}') from e
252252

lib/matplotlib/tests/test_rcparams.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,7 @@ def generate_validator_testcases(valid):
254254
for _ in ('1.5, 2.5', [1.5, 2.5], [1.5, 2.5],
255255
(1.5, 2.5), np.array((1.5, 2.5)))),
256256
'fail': ((_, ValueError)
257-
for _ in ('aardvark', ('a', 1),
258-
(1, 2, 3)
259-
))
257+
for _ in ('aardvark', ('a', 1), (1, 2, 3), (None, ), None))
260258
},
261259
{'validator': validate_cycler,
262260
'success': (('cycler("color", "rgb")',

0 commit comments

Comments
 (0)