From 214dbcaeb092ad8ad16f5f4cbc1438fc83de311e Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 11 Apr 2019 15:15:03 +0200 Subject: [PATCH] Better handle deprecated rcParams. - Don't trigger a deprecation in repr() (e.g., in `$ pydoc matplotlib`). - Don't trigger a deprecation in test_style.py::test_alias. --- lib/matplotlib/__init__.py | 5 +++-- lib/matplotlib/tests/test_style.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 99f74864c872..14981df8d4f8 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -824,8 +824,9 @@ def __getitem__(self, key): def __repr__(self): class_name = self.__class__.__name__ indent = len(class_name) + 1 - repr_split = pprint.pformat(dict(self), indent=1, - width=80 - indent).split('\n') + with cbook._suppress_matplotlib_deprecation_warning(): + repr_split = pprint.pformat(dict(self), indent=1, + width=80 - indent).split('\n') repr_indented = ('\n' + ' ' * indent).join(repr_split) return '{}({})'.format(class_name, repr_indented) diff --git a/lib/matplotlib/tests/test_style.py b/lib/matplotlib/tests/test_style.py index 0fd141aec647..552b87e4aa14 100644 --- a/lib/matplotlib/tests/test_style.py +++ b/lib/matplotlib/tests/test_style.py @@ -145,7 +145,7 @@ def test_alias(equiv_styles): rc_dicts = [] for sty in equiv_styles: with style.context(sty): - rc_dicts.append(dict(mpl.rcParams)) + rc_dicts.append(mpl.rcParams.copy()) rc_base = rc_dicts[0] for nm, rc in zip(equiv_styles[1:], rc_dicts[1:]):