Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 47375a0

Browse files
authored
Merge pull request #15990 from anntzer/k31
Remove deprecated support for setting single property via multiple aliases
2 parents d3603bf + 1b14ef9 commit 47375a0

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

doc/api/next_api_changes/behaviour.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ and `.pyplot.yticks` would result in
5050
TypeError: object of type 'NoneType' has no len()
5151

5252
It now raises a ``TypeError`` with a proper description of the error.
53+
54+
Setting the same property under multiple aliases now raises a TypeError
55+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
56+
Previously, calling e.g. ``plot(..., color=somecolor, c=othercolor)`` would
57+
emit a warning because ``color`` and ``c`` actually map to the same Artist
58+
property. This now raises a TypeError.

lib/matplotlib/cbook/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,11 +1763,9 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
17631763
if tmp:
17641764
ret[canonical] = tmp[-1]
17651765
if len(tmp) > 1:
1766-
warn_deprecated(
1767-
"3.1", message=f"Saw kwargs {seen!r} which are all "
1768-
f"aliases for {canonical!r}. Kept value from "
1769-
f"{seen[-1]!r}. Passing multiple aliases for the same "
1770-
f"property will raise a TypeError %(removal)s.")
1766+
raise TypeError("Got the following keyword arguments which "
1767+
"are aliases of one another: {}"
1768+
.format(", ".join(map(repr, seen))))
17711769

17721770
# at this point we know that all keys which are aliased are removed, update
17731771
# the return dictionary from the cleaned local copy of the input

lib/matplotlib/tests/test_cbook.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,12 @@ def test_sanitize_sequence():
301301
fail_mapping = (
302302
({'a': 1}, {'forbidden': ('a')}),
303303
({'a': 1}, {'required': ('b')}),
304-
({'a': 1, 'b': 2}, {'required': ('a'), 'allowed': ()})
305-
)
306-
307-
warn_passing_mapping = (
308-
({'a': 1, 'b': 2}, {'a': 1}, {'alias_mapping': {'a': ['b']}}, 1),
309-
({'a': 1, 'b': 2}, {'a': 1},
310-
{'alias_mapping': {'a': ['b']}, 'allowed': ('a',)}, 1),
311-
({'a': 1, 'b': 2}, {'a': 2}, {'alias_mapping': {'a': ['a', 'b']}}, 1),
312-
({'a': 1, 'b': 2, 'c': 3}, {'a': 1, 'c': 3},
313-
{'alias_mapping': {'a': ['b']}, 'required': ('a', )}, 1),
304+
({'a': 1, 'b': 2}, {'required': ('a'), 'allowed': ()}),
305+
({'a': 1, 'b': 2}, {'alias_mapping': {'a': ['b']}}),
306+
({'a': 1, 'b': 2}, {'alias_mapping': {'a': ['b']}, 'allowed': ('a',)}),
307+
({'a': 1, 'b': 2}, {'alias_mapping': {'a': ['a', 'b']}}),
308+
({'a': 1, 'b': 2, 'c': 3},
309+
{'alias_mapping': {'a': ['b']}, 'required': ('a', )}),
314310
)
315311

316312
pass_mapping = (
@@ -337,15 +333,6 @@ def test_normalize_kwargs_fail(inp, kwargs_to_norm):
337333
cbook.normalize_kwargs(inp, **kwargs_to_norm)
338334

339335

340-
@pytest.mark.parametrize('inp, expected, kwargs_to_norm, warn_count',
341-
warn_passing_mapping)
342-
def test_normalize_kwargs_warn(inp, expected, kwargs_to_norm, warn_count):
343-
with warnings.catch_warnings(record=True) as w:
344-
warnings.simplefilter("always")
345-
assert expected == cbook.normalize_kwargs(inp, **kwargs_to_norm)
346-
assert len(w) == warn_count
347-
348-
349336
@pytest.mark.parametrize('inp, expected, kwargs_to_norm',
350337
pass_mapping)
351338
def test_normalize_kwargs_pass(inp, expected, kwargs_to_norm):

0 commit comments

Comments
 (0)