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

Skip to content

Commit 79189ce

Browse files
committed
Mark artist property aliases explicitly
1 parent e6e20e3 commit 79189ce

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

lib/matplotlib/_api/__init__.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
in your own code. We may change the API at any time with no warning.
1010
1111
"""
12-
12+
from collections import namedtuple
1313
import functools
1414
import itertools
1515
import re
@@ -58,6 +58,16 @@ def fget(self):
5858
return self._fget
5959

6060

61+
ArtistPropertyInfo = namedtuple('ArtistPropertyInfo', 'kwdoc, is_alias')
62+
63+
64+
def artist_property(kwdoc=None, is_alias=False):
65+
def decorator(func):
66+
func._artist_property = ArtistPropertyInfo(kwdoc, is_alias)
67+
return func
68+
return decorator
69+
70+
6171
# In the following check_foo() functions, the first parameter starts with an
6272
# underscore because it is intended to be positional-only (e.g., so that
6373
# `_api.check_isinstance([...], types=foo)` doesn't fail.
@@ -261,6 +271,8 @@ def method(self, *args, **kwargs):
261271
method = make_alias(prefix + prop)
262272
method.__name__ = prefix + alias
263273
method.__doc__ = "Alias for `{}`.".format(prefix + prop)
274+
method._artist_property = \
275+
ArtistPropertyInfo(kwdoc=None, is_alias=True)
264276
setattr(cls, prefix + alias, method)
265277
if not exists:
266278
raise ValueError(

lib/matplotlib/artist.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,12 @@ def is_alias(self, o):
14901490
ds = inspect.getdoc(o)
14911491
if ds is None:
14921492
return False
1493-
return ds.startswith('Alias for ')
1493+
result = ds.startswith('Alias for ')
1494+
alt_result = (o._artist_property.is_alias
1495+
if hasattr(o, '_artist_property')
1496+
else False)
1497+
assert result == alt_result
1498+
return result
14941499

14951500
def aliased_name(self, s):
14961501
"""

lib/matplotlib/text.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,7 @@ def get_parse_math(self):
13041304
"""Return whether mathtext parsing is considered for this `Text`."""
13051305
return self._parse_math
13061306

1307+
@_api.artist_property(is_alias=True)
13071308
def set_fontname(self, fontname):
13081309
"""
13091310
Alias for `set_family`.

0 commit comments

Comments
 (0)