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

Skip to content

Fix ArtistInspector.get_aliases. #12037

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
Sep 10, 2018
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
12 changes: 12 additions & 0 deletions doc/users/next_whats_new/2018-09-06-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
:orphan:

Return type of ArtistInspector.get_aliases changed
``````````````````````````````````````````````````

`ArtistInspector.get_aliases` previously returned the set of aliases as
``{fullname: {alias1: None, alias2: None, ...}}``. The dict-to-None mapping
was used to simulate a set in earlier versions of Python. It has now been
replaced by a set, i.e. ``{fullname: {alias1, alias2, ...}}``.

This value is also stored in `ArtistInspector.aliasd`, which has likewise
changed.
15 changes: 7 additions & 8 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,15 +1189,14 @@ def __init__(self, o):

def get_aliases(self):
"""
Get a dict mapping *fullname* -> *alias* for each *alias* in
the :class:`~matplotlib.artist.ArtistInspector`.
Get a dict mapping property fullnames to sets of aliases for each alias
in the :class:`~matplotlib.artist.ArtistInspector`.

e.g., for lines::

{'markerfacecolor': 'mfc',
'linewidth' : 'lw',
{'markerfacecolor': {'mfc'},
'linewidth' : {'lw'},
}

"""
names = [name for name in dir(self.o)
if name.startswith(('set_', 'get_'))
Expand All @@ -1207,9 +1206,9 @@ def get_aliases(self):
func = getattr(self.o, name)
if not self.is_alias(func):
continue
docstring = func.__doc__
fullname = docstring.replace('`', '')[10:]
aliases.setdefault(fullname[4:], {})[name[4:]] = None
propname = re.search("`({}.*)`".format(name[:4]), # get_.*/set_.*
func.__doc__).group(1)
aliases.setdefault(propname, set()).add(name[4:])
return aliases

_get_valid_values_regex = re.compile(
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# allows all Line2D kwargs.
_line_AI = artist.ArtistInspector(mlines.Line2D)
_line_param_names = _line_AI.get_setters()
_line_param_aliases = [list(d.keys())[0] for d in _line_AI.aliasd.values()]
_line_param_aliases = [list(d)[0] for d in _line_AI.aliasd.values()]
_gridline_param_names = ['grid_' + name
for name in _line_param_names + _line_param_aliases]

Expand Down