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

Skip to content

Commit e74a743

Browse files
committed
Fix ArtistInspector.get_aliases.
The docstring parsing in get_aliases was brittle and didn't handle the final dot that cbook._define_aliases added to the docstring, so as of master it would return the keys with an additional dot. Instead, use a regex which will loudly error out if the format is incorrect. Also replace {key: None, ...} mapping simulating a set to, well, a set. (The use of sets instead of lists was added in ed9c2b5 apparently to handle the case where the same alias is added twice.) (Yes, the whole alias machinery could now be simplified e.g. by adding an `is_mpl_alias` attribute on the aliases instead.)
1 parent 248399e commit e74a743

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Return type of ArtistInspector.get_aliases changed
2+
``````````````````````````````````````````````````
3+
4+
`ArtistInspector.get_aliases` previously returned the set of aliases as
5+
``{fullname: {alias1: None, alias2: None, ...}}``. The dict-to-None mapping
6+
was used to simulate a set in earlier versions of Python. It has now been
7+
replaced by a set, i.e. ``{fullname: {alias1, alias2, ...}}``.
8+
9+
This value is also stored in `ArtistInspector.aliasd`, which has likewise
10+
changed.

lib/matplotlib/artist.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,15 +1189,14 @@ def __init__(self, o):
11891189

11901190
def get_aliases(self):
11911191
"""
1192-
Get a dict mapping *fullname* -> *alias* for each *alias* in
1193-
the :class:`~matplotlib.artist.ArtistInspector`.
1192+
Get a dict mapping property fullnames to sets of aliases for each alias
1193+
in the :class:`~matplotlib.artist.ArtistInspector`.
11941194
11951195
e.g., for lines::
11961196
1197-
{'markerfacecolor': 'mfc',
1198-
'linewidth' : 'lw',
1197+
{'markerfacecolor': {'mfc'},
1198+
'linewidth' : {'lw'},
11991199
}
1200-
12011200
"""
12021201
names = [name for name in dir(self.o)
12031202
if name.startswith(('set_', 'get_'))
@@ -1207,9 +1206,9 @@ def get_aliases(self):
12071206
func = getattr(self.o, name)
12081207
if not self.is_alias(func):
12091208
continue
1210-
docstring = func.__doc__
1211-
fullname = docstring.replace('`', '')[10:]
1212-
aliases.setdefault(fullname[4:], {})[name[4:]] = None
1209+
propname = re.search("`({}.*)`".format(name[:4]), # get_.*/set_.*
1210+
func.__doc__).group(1)
1211+
aliases.setdefault(propname, set()).add(name[4:])
12131212
return aliases
12141213

12151214
_get_valid_values_regex = re.compile(

lib/matplotlib/axis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# allows all Line2D kwargs.
3131
_line_AI = artist.ArtistInspector(mlines.Line2D)
3232
_line_param_names = _line_AI.get_setters()
33-
_line_param_aliases = [list(d.keys())[0] for d in _line_AI.aliasd.values()]
33+
_line_param_aliases = [list(d)[0] for d in _line_AI.aliasd.values()]
3434
_gridline_param_names = ['grid_' + name
3535
for name in _line_param_names + _line_param_aliases]
3636

0 commit comments

Comments
 (0)