8000 Store aliases in set, support inheritance. · matplotlib/matplotlib@b3d4636 · GitHub
[go: up one dir, main page]

Skip to content

Commit b3d4636

Browse files
committed
Store aliases in set, support inheritance.
1 parent 52c6c77 commit b3d4636

File tree

5 files changed

+42
-33
lines changed

5 files changed

+42
-33
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import six
1212
from six.moves import xrange, zip
1313
import collections
14+
import copy
1415
import datetime
1516
import errno
1617
import functools
@@ -2774,7 +2775,7 @@ def _define_aliases(alias_d, cls=None):
27742775
27752776
Use as ::
27762777
2777-
@cbook._define_aliases({"property": ["alias", ...], ...})
2778+
@cbook._define_aliases({"property": {"alias", ...}, ...})
27782779
class C: ...
27792780
27802781
For each property, if the corresponding ``get_property`` is defined in the
@@ -2804,7 +2805,15 @@ def method(self, *args, **kwargs):
28042805
method.__doc__ = "alias for `{}`".format(prefix + prop)
28052806
setattr(cls, prefix + alias, method)
28062807
if not exists:
2807-
raise ValueError("property {} does not exist".format(prop))
2808+
raise ValueError(
2809+
"Neither getter nor setter exists for {!r}".format(prop))
28082810

2809-
cls._alias_map = alias_d
2811+
try:
2812+
# Deepcopy the inherited alias map if any, to avoid modifying the
2813+
# parent class.
2814+
cls._alias_map = copy.deepcopy(cls._alias_map)
2815+
except AttributeError:
2816+
cls._alias_map = {}
2817+
for prop, aliases in alias_d.items():
2818+
cls._alias_map.setdefault(prop, set()).update(aliases)
28102819
return cls

lib/matplotlib/collections.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838

3939

4040
@cbook._define_aliases({
41-
"antialiased": ["antialiaseds"],
42-
"edgecolor": ["edgecolors"],
43-
"facecolor": ["facecolors"],
44-
"linestyle": ["linestyles", "dashes"],
45-
"linewidth": ["linewidths", "lw"],
41+
"antialiased": {"antialiaseds"},
42+
"edgecolor": {"edgecolors"},
43+
"facecolor": {"facecolors"},
44+
"linestyle": {"linestyles", "dashes"},
45+
"linewidth": {"linewidths", "lw"},
4646
})
4747
class Collection(artist.Artist, cm.ScalarMappable):
4848
"""

lib/matplotlib/lines.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,15 @@ def _slice_or_none(in_v, slc):
231231

232232

233233
@cbook._define_aliases({
234-
"antialiased": ["aa"],
235-
"color": ["c"],
236-
"linestyle": ["ls"],
237-
"linewidth": ["lw"],
238-
"markeredgecolor": ["mec"],
239-
"markeredgewidth": ["mew"],
240-
"markerfacecolor": ["mfc"],
241-
"markerfacecoloralt": ["mfcalt"],
242-
"markersize": ["ms"],
234+
"antialiased": {"aa"},
235+
"color": {"c"},
236+
"linestyle": {"ls"},
237+
"linewidth": {"lw"},
238+
"markeredgecolor": {"mec"},
239+
"markeredgewidth": {"mew"},
240+
"markerfacecolor": {"mfc"},
241+
"markerfacecoloralt": {"mfcalt"},
242+
"markersize": {"ms"},
243243
})
244244
class Line2D(Artist):
245245
"""

lib/matplotlib/patches.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525

2626

2727
@cbook._define_aliases({
28-
"antialiased": ["aa"],
29-
"edgecolor": ["ec"],
30-
"facecolor": ["fc"],
31-
"linewidth": ["lw"],
32-
"linestyle": ["ls"],
28+
"antialiased": {"aa"},
29+
"edgecolor": {"ec"},
30+
"facecolor": {"fc"},
31+
"linewidth": {"lw"},
32+
"linestyle": {"ls"},
3333
})
3434
class Patch(artist.Artist):
3535
"""

lib/matplotlib/text.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,17 @@ def _get_textbox(text, renderer):
126126

127127

128128
@cbook._define_aliases({
129-
"family": ["fontfamily"],
130-
"fontproperties": ["font_properties"],
131-
"horizontalalignment": ["ha"],
132-
"multialignment": ["ma"],
133-
"name": ["fontname"],
134-
"size": ["fontsize"],
135-
"stretch": ["fontstretch"],
136-
"style": ["fontstyle"],
137-
"variant": ["fontvariant"],
138-
"verticalalignment": ["va"],
139-
"weight": ["fontweight"],
129+
"family": {"fontfamily"},
130+
"fontproperties": {"font_properties"},
131+
"horizontalalignment": {"ha"},
132+
"multialignment": {"ma"},
133+
"name": {"fontname"},
134+
"size": {"fontsize"},
135+
"stretch": {"fontstretch"},
136+
"style": {"fontstyle"},
137+
"variant": {"fontvariant"},
138+
"verticalalignment": {"va"},
139+
"weight": {"fontweight"},
140140
})
141141
class Text(Artist):
142142
"""

0 commit comments

Comments
 (0)
0