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

Skip to content

Commit 46eb9b6

Browse files
authored
Merge pull request #12037 from anntzer/artistinspector
Fix ArtistInspector.get_aliases.
2 parents 5e20d9b + b8cd2d5 commit 46eb9b6

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

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

lib/matplotlib/artist.py

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

11741174
def get_aliases(self):
11751175
"""
1176-
Get a dict mapping *fullname* -> *alias* for each *alias* in
1177-
the :class:`~matplotlib.artist.ArtistInspector`.
1176+
Get a dict mapping property fullnames to sets of aliases for each alias
1177+
in the :class:`~matplotlib.artist.ArtistInspector`.
11781178
11791179
e.g., for lines::
11801180
1181-
{'markerfacecolor': 'mfc',
1182-
'linewidth' : 'lw',
1181+
{'markerfacecolor': {'mfc'},
1182+
'linewidth' : {'lw'},
11831183
}
1184-
11851184
"""
11861185
names = [name for name in dir(self.o)
11871186
if name.startswith(('set_', 'get_'))
@@ -1191,9 +1190,9 @@ def get_aliases(self):
11911190
func = getattr(self.o, name)
11921191
if not self.is_alias(func):
11931192
continue
1194-
docstring = func.__doc__
1195-
fullname = docstring.replace('`', '')[10:]
1196-
aliases.setdefault(fullname[4:], {})[name[4:]] = None
1193+
propname = re.search("`({}.*)`".format(name[:4]), # get_.*/set_.*
1194+
func.__doc__).group(1)
1195+
aliases.setdefault(propname, set()).add(name[4:])
11971196
return aliases
11981197

11991198
_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)