8000 Simplify normalize_kwargs. · matplotlib/matplotlib@8cec64d · GitHub
[go: up one dir, main page]

Skip to content

Commit 8cec64d

Browse files
committed
Simplify 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.
1 parent 9984f9c commit 8cec64d

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,7 @@ Revert deprecation \*min, \*max keyword arguments to ``set_x/y/zlim_3d()``
7373
These keyword arguments were deprecated in 3.0, alongside with the respective
7474
parameters in ``set_xlim()`` / ``set_ylim()``. The deprecations of the 2D
7575
versions were already reverted in in 3.1.
76+
77+
*required*, *forbidden* and *allowed* parameters of `.cbook.normalize_kwargs`
78+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
79+
These parameters are deprecated.

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3881,8 +3881,7 @@ def line_props_with_rcdefaults(subkey, explicit, zdelta=0):
38813881
if k.startswith(f'boxplot.{subkey}')}
38823882
d['zorder'] = zorder + zdelta
38833883
if explicit is not None:
3884-
d.update(
3885-
cbook.normalize_kwargs(explicit, mlines.Line2D._alias_map))
3884+
d.update(cbook.normalize_kwargs(explicit, mlines.Line2D))
38863885
return d
38873886

38883887
# box properties
@@ -3897,8 +3896,7 @@ def line_props_with_rcdefaults(subkey, explicit, zdelta=0):
38973896
)
38983897
if boxprops is not None:
38993898
final_boxprops.update(
3900-
cbook.normalize_kwargs(
3901-
boxprops, mpatches.PathPatch._alias_map))
3899+
cbook.normalize_kwargs(boxprops, mpatches.PathPatch))
39023900
else:
39033901
final_boxprops = line_props_with_rcdefaults('boxprops', boxprops)
39043902
final_whiskerprops = line_props_with_rcdefaults(

lib/matplotlib/cbook/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,9 @@ def sanitize_sequence(data):
16761676
else data)
16771677

16781678

1679+
@_delete_parameter("3.3", "required")
1680+
@_delete_parameter("3.3", "forbidden")
1681+
@_delete_parameter("3.3", "allowed")
16791682
def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
16801683
allowed=None):
16811684
"""
@@ -1707,16 +1710,16 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
17071710
mapping.
17081711
17091712
required : list of str, optional
1710-
A list of keys that must be in *kws*.
1713+
A list of keys that must be in *kws*. This parameter is deprecated.
17111714
17121715
forbidden : list of str, optional
1713-
A list of keys which may not be in *kw*.
1716+
A list of keys which may not be in *kw*. This parameter is deprecated.
17141717
17151718
allowed : list of str, optional
17161719
A list of allowed fields. If this not None, then raise if
17171720
*kw* contains any keys not in the union of *required*
17181721
and *allowed*. To allow only the required fields pass in
1719-
an empty tuple ``allowed=()``.
1722+
an empty tuple ``allowed=()``. This parameter is deprecated.
17201723
17211724
Raises
17221725
------

lib/matplotlib/tests/test_cbook.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,17 +329,17 @@ def test_sanitize_sequence():
329329

330330
@pytest.mark.parametrize('inp, kwargs_to_norm', fail_mapping)
331331
def test_normalize_kwargs_fail(inp, kwargs_to_norm):
332-
with pytest.raises(TypeError):
332+
with pytest.raises(TypeError), \
333+
cbook._suppress_matplotlib_deprecation_warning():
333334
cbook.normalize_kwargs(inp, **kwargs_to_norm)
334335

335336

336337
@pytest.mark.parametrize('inp, expected, kwargs_to_norm',
337338
pass_mapping)
338-
def test_normalize_kwargs_pass(inp, expected, kwargs_to_norm):
339-
with warnings.catch_warnings(record=True) as w:
340-
warnings.simplefilter("always")
339+
def test_normalize_kwargs_pass(inp, expected, kwargs_to_norm, recwarn):
340+
with cbook._suppress_matplotlib_deprecation_warning():
341341
assert expected == cbook.normalize_kwargs(inp, **kwargs_to_norm)
342-
assert len(w) == 0
342+
assert len(recwarn) == 0
343343

344344

345345
def test_warn_external_frame_embedded_python():

0 commit comments

Comments
 (0)
0