Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9c3eed4

Browse filesBrowse 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
Copy full SHA for 9c3eed4

File tree

Expand file treeCollapse file tree

2 files changed

+2
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+2
-4
lines changed

‎lib/matplotlib/rcsetup.py

Copy file name to clipboardExpand all lines: lib/matplotlib/rcsetup.py
+1-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_rcparams.py
+1-3Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.