Skip to content

Support normalize_kwargs(None) (== {}). #19014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2020
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
23 changes: 10 additions & 13 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3868,23 +3868,20 @@ def line_props_with_rcdefaults(subkey, explicit, zdelta=0,
d['zorder'] = zorder + zdelta
if not use_marker:
d['marker'] = ''
if explicit is not None:
d.update(cbook.normalize_kwargs(explicit, mlines.Line2D))
d.update(cbook.normalize_kwargs(explicit, mlines.Line2D))
return d

# box properties
if patch_artist:
final_boxprops = dict(
linestyle=rcParams['boxplot.boxprops.linestyle'],
linewidth=rcParams['boxplot.boxprops.linewidth'],
edgecolor=rcParams['boxplot.boxprops.color'],
facecolor=('white' if rcParams['_internal.classic_mode'] else
rcParams['patch.facecolor']),
zorder=zorder,
)
if boxprops is not None:
final_boxprops.update(
cbook.normalize_kwargs(boxprops, mpatches.PathPatch))
final_boxprops = {
'linestyle': rcParams['boxplot.boxprops.linestyle'],
'linewidth': rcParams['boxplot.boxprops.linewidth'],
'edgecolor': rcParams['boxplot.boxprops.color'],
'facecolor': ('white' if rcParams['_internal.classic_mode']
else rcParams['patch.facecolor']),
'zorder': zorder,
**cbook.normalize_kwargs(boxprops, mpatches.PathPatch)
}
else:
final_boxprops = line_props_with_rcdefaults('boxprops', boxprops,
use_marker=False)
Expand Down
9 changes: 7 additions & 2 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1714,8 +1714,10 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),

Parameters
----------
kw : dict
A dict of keyword arguments.
kw : dict or None
A dict of keyword arguments. None is explicitly supported and treated
as an empty dict, to support functions with an optional parameter of
the form ``props=None``.

alias_mapping : dict or Artist subclass or Artist instance, optional
A mapping between a canonical name to a list of
Expand Down Expand Up @@ -1747,6 +1749,9 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
"""
from matplotlib.artist import Artist

if kw is None:
return {}

# deal with default value of alias_mapping
if alias_mapping is None:
alias_mapping = dict()
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/tests/test_cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ def test_sanitize_sequence():
)

pass_mapping = (
(None, {}, {}),
({'a': 1, 'b': 2}, {'a': 1, 'b': 2}, {}),
({'b': 2}, {'a': 2}, {'alias_mapping': {'a': ['a', 'b']}}),
({'b': 2}, {'a': 2},
Expand Down
12 changes: 5 additions & 7 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1826,11 +1826,10 @@ class ToolHandles:

def __init__(self, ax, x, y, marker='o', marker_props=None, useblit=True):
self.ax = ax
props = dict(marker=marker, markersize=7, markerfacecolor='w',
linestyle='none', alpha=0.5, visible=False,
label='_nolegend_')
props.update(cbook.normalize_kwargs(marker_props, Line2D._alias_map)
if marker_props is not None else {})
props = {'marker': marker, 'markersize': 7, 'markerfacecolor': 'w',
'linestyle': 'none', 'alpha': 0.5, 'visible': False,
'label': '_nolegend_',
**cbook.normalize_kwargs(marker_props, Line2D._alias_map)}
self._markers = Line2D(x, y, animated=useblit, **props)
self.ax.add_line(self._markers)
self.artist = self._markers
Expand Down Expand Up @@ -2000,8 +1999,7 @@ def onselect(eclick: MouseEvent, erelease: MouseEvent)
props = dict(markeredgecolor='r')
else:
props = dict(markeredgecolor=rectprops.get('edgecolor', 'r'))
props.update(cbook.normalize_kwargs(marker_props, Line2D._alias_map)
if marker_props is not None else {})
props.update(cbook.normalize_kwargs(marker_props, Line2D._alias_map))
self._corner_order = ['NW', 'NE', 'SE', 'SW']
xc, yc = self.corners
self._corner_handles = ToolHandles(self.ax, xc, yc, marker_props=props,
Expand Down