From 1b14ef9610938d0443622cc324d3f56fbf50a7d9 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 20 Dec 2019 18:01:23 +0100 Subject: [PATCH] Remove deprecated support for setting single property via multiple aliases. --- doc/api/next_api_changes/behaviour.rst | 6 ++++++ lib/matplotlib/cbook/__init__.py | 8 +++----- lib/matplotlib/tests/test_cbook.py | 25 ++++++------------------- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/doc/api/next_api_changes/behaviour.rst b/doc/api/next_api_changes/behaviour.rst index eaf3825a6e0f..9796a64ad84f 100644 --- a/doc/api/next_api_changes/behaviour.rst +++ b/doc/api/next_api_changes/behaviour.rst @@ -50,3 +50,9 @@ and `.pyplot.yticks` would result in TypeError: object of type 'NoneType' has no len() It now raises a ``TypeError`` with a proper description of the error. + +Setting the same property under multiple aliases now raises a TypeError +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Previously, calling e.g. ``plot(..., color=somecolor, c=othercolor)`` would +emit a warning because ``color`` and ``c`` actually map to the same Artist +property. This now raises a TypeError. diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index 3ac5041d2363..c856aad7651d 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -1763,11 +1763,9 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(), if tmp: ret[canonical] = tmp[-1] if len(tmp) > 1: - warn_deprecated( - "3.1", message=f"Saw kwargs {seen!r} which are all " - f"aliases for {canonical!r}. Kept value from " - f"{seen[-1]!r}. Passing multiple aliases for the same " - f"property will raise a TypeError %(removal)s.") + raise TypeError("Got the following keyword arguments which " + "are aliases of one another: {}" + .format(", ".join(map(repr, seen)))) # at this point we know that all keys which are aliased are removed, update # the return dictionary from the cleaned local copy of the input diff --git a/lib/matplotlib/tests/test_cbook.py b/lib/matplotlib/tests/test_cbook.py index 017b758f395c..b679783bb695 100644 --- a/lib/matplotlib/tests/test_cbook.py +++ b/lib/matplotlib/tests/test_cbook.py @@ -301,16 +301,12 @@ def test_sanitize_sequence(): fail_mapping = ( ({'a': 1}, {'forbidden': ('a')}), ({'a': 1}, {'required': ('b')}), - ({'a': 1, 'b': 2}, {'required': ('a'), 'allowed': ()}) -) - -warn_passing_mapping = ( - ({'a': 1, 'b': 2}, {'a': 1}, {'alias_mapping': {'a': ['b']}}, 1), - ({'a': 1, 'b': 2}, {'a': 1}, - {'alias_mapping': {'a': ['b']}, 'allowed': ('a',)}, 1), - ({'a': 1, 'b': 2}, {'a': 2}, {'alias_mapping': {'a': ['a', 'b']}}, 1), - ({'a': 1, 'b': 2, 'c': 3}, {'a': 1, 'c': 3}, - {'alias_mapping': {'a': ['b']}, 'required': ('a', )}, 1), + ({'a': 1, 'b': 2}, {'required': ('a'), 'allowed': ()}), + ({'a': 1, 'b': 2}, {'alias_mapping': {'a': ['b']}}), + ({'a': 1, 'b': 2}, {'alias_mapping': {'a': ['b']}, 'allowed': ('a',)}), + ({'a': 1, 'b': 2}, {'alias_mapping': {'a': ['a', 'b']}}), + ({'a': 1, 'b': 2, 'c': 3}, + {'alias_mapping': {'a': ['b']}, 'required': ('a', )}), ) pass_mapping = ( @@ -337,15 +333,6 @@ def test_normalize_kwargs_fail(inp, kwargs_to_norm): cbook.normalize_kwargs(inp, **kwargs_to_norm) -@pytest.mark.parametrize('inp, expected, kwargs_to_norm, warn_count', - warn_passing_mapping) -def test_normalize_kwargs_warn(inp, expected, kwargs_to_norm, warn_count): - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always") - assert expected == cbook.normalize_kwargs(inp, **kwargs_to_norm) - assert len(w) == warn_count - - @pytest.mark.parametrize('inp, expected, kwargs_to_norm', pass_mapping) def test_normalize_kwargs_pass(inp, expected, kwargs_to_norm):