From b4ee5dbd8a791c3cf36ca3557f0fba056e6a9a00 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 10 Mar 2017 11:11:14 -0800 Subject: [PATCH] Set __name__ for list validators in rcsetup. This avoids having many validators all named `f`, which makes profiling a bit difficult (it appears that repeated validation of rcparams when resetting the style at the beginning of each test instance contributes quite a bit to the total test time). Instead, the list validator based on scalar validator function `validate_foo` is now `__name__`d `validate_foolist`, and the list validator based on scalar validator class `ValidateFoo` is now `__name__`d `ValidateFooList`. --- lib/matplotlib/rcsetup.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 050e8901f98c..8e3d568c31a7 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -95,8 +95,13 @@ def f(s): return [scalar_validator(v) for v in s if not isinstance(v, six.string_types) or v] else: - msg = "{0!r} must be of type: string or non-dictionary iterable.".format(s) - raise ValueError(msg) + raise ValueError("{!r} must be of type: string or non-dictionary " + "iterable".format(s)) + # Cast `str` to keep Py2 happy despite `unicode_literals`. + try: + f.__name__ = str("{}list".format(scalar_validator.__name__)) + except AttributeError: # class instance. + f.__name__ = str("{}List".format(type(scalar_validator).__name__)) f.__doc__ = scalar_validator.__doc__ return f