From 498f41d68126d0be18a906eb48940d938fe34246 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 20 Dec 2019 17:51:28 +0100 Subject: [PATCH] Deprecate unused features of normalize_kwargs. The required, forbidden and allowed kwargs of normalize_kwargs have never been used and add a significant amount of complexity to the implementation of normalize kwargs, so get rid of them. --- doc/api/next_api_changes/deprecations.rst | 4 ++++ lib/matplotlib/axes/_axes.py | 6 ++---- lib/matplotlib/cbook/__init__.py | 9 ++++++--- lib/matplotlib/tests/test_cbook.py | 11 +++++------ 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/doc/api/next_api_changes/deprecations.rst b/doc/api/next_api_changes/deprecations.rst index dae361ec5f6b..4719e944aedf 100644 --- a/doc/api/next_api_changes/deprecations.rst +++ b/doc/api/next_api_changes/deprecations.rst @@ -159,3 +159,7 @@ e.g. `.FuncFormatter`. ``OldAutoLocator`` ~~~~~~~~~~~~~~~~~~ This ticker is deprecated. + +*required*, *forbidden* and *allowed* parameters of `.cbook.normalize_kwargs` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +These parameters are deprecated. diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 03bce7b86aed..e9c7bcc8d829 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -3881,8 +3881,7 @@ def line_props_with_rcdefaults(subkey, explicit, zdelta=0, if not use_marker: d['marker'] = '' if explicit is not None: - d.update( - cbook.normalize_kwargs(explicit, mlines.Line2D._alias_map)) + d.update(cbook.normalize_kwargs(explicit, mlines.Line2D)) return d # box properties @@ -3897,8 +3896,7 @@ def line_props_with_rcdefaults(subkey, explicit, zdelta=0, ) if boxprops is not None: final_boxprops.update( - cbook.normalize_kwargs( - boxprops, mpatches.PathPatch._alias_map)) + cbook.normalize_kwargs(boxprops, mpatches.PathPatch)) else: final_boxprops = line_props_with_rcdefaults('boxprops', boxprops, use_marker=False) diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index 5a2297c4d127..5b4fad44cecf 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -1682,6 +1682,9 @@ def sanitize_sequence(data): else data) +@_delete_parameter("3.3", "required") +@_delete_parameter("3.3", "forbidden") +@_delete_parameter("3.3", "allowed") def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(), allowed=None): """ @@ -1713,16 +1716,16 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(), mapping. required : list of str, optional - A list of keys that must be in *kws*. + A list of keys that must be in *kws*. This parameter is deprecated. forbidden : list of str, optional - A list of keys which may not be in *kw*. + A list of keys which may not be in *kw*. This parameter is deprecated. allowed : list of str, optional A list of allowed fields. If this not None, then raise if *kw* contains any keys not in the union of *required* and *allowed*. To allow only the required fields pass in - an empty tuple ``allowed=()``. + an empty tuple ``allowed=()``. This parameter is deprecated. Raises ------ diff --git a/lib/matplotlib/tests/test_cbook.py b/lib/matplotlib/tests/test_cbook.py index 9eb156f3d2a6..1563f82ac123 100644 --- a/lib/matplotlib/tests/test_cbook.py +++ b/lib/matplotlib/tests/test_cbook.py @@ -1,7 +1,6 @@ import itertools import pickle from weakref import ref -import warnings from unittest.mock import patch, Mock from datetime import datetime @@ -329,17 +328,17 @@ def test_sanitize_sequence(): @pytest.mark.parametrize('inp, kwargs_to_norm', fail_mapping) def test_normalize_kwargs_fail(inp, kwargs_to_norm): - with pytest.raises(TypeError): + with pytest.raises(TypeError), \ + cbook._suppress_matplotlib_deprecation_warning(): cbook.normalize_kwargs(inp, **kwargs_to_norm) @pytest.mark.parametrize('inp, expected, kwargs_to_norm', pass_mapping) -def test_normalize_kwargs_pass(inp, expected, kwargs_to_norm): - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always") +def test_normalize_kwargs_pass(inp, expected, kwargs_to_norm, recwarn): + with cbook._suppress_matplotlib_deprecation_warning(): assert expected == cbook.normalize_kwargs(inp, **kwargs_to_norm) - assert len(w) == 0 + assert len(recwarn) == 0 def test_warn_external_frame_embedded_python():