Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/api/next_api_changes/behaviour.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 3 additions & 5 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 6 additions & 19 deletions lib/matplotlib/tests/test_cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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):
Expand Down