diff --git a/doc/devel/documenting_mpl.rst b/doc/devel/documenting_mpl.rst index 72f1bedd22d6..9b8dec1ed988 100644 --- a/doc/devel/documenting_mpl.rst +++ b/doc/devel/documenting_mpl.rst @@ -729,7 +729,7 @@ gets interpolated into the docstring. Note that this scheme does not work for decorating an Artist's ``__init__``, as the subclass and its properties are not defined yet at that point. Instead, ``@_docstring.interpd`` can be used to decorate the class itself -- at that -point, `.kwdoc` can list the properties and interpolate them into +point, `.artist.kwdoc` can list the properties and interpolate them into ``__init__.__doc__``. diff --git a/lib/matplotlib/_api/__init__.py b/lib/matplotlib/_api/__init__.py index 483b810e5d7d..1aec5be218ea 100644 --- a/lib/matplotlib/_api/__init__.py +++ b/lib/matplotlib/_api/__init__.py @@ -9,7 +9,7 @@ in your own code. We may change the API at any time with no warning. """ - +from collections import namedtuple import functools import itertools import re @@ -58,6 +58,16 @@ def fget(self): return self._fget +ArtistPropertyInfo = namedtuple('ArtistPropertyInfo', 'kwdoc, is_alias') + + +def artist_property(kwdoc=None, is_alias=False): + def decorator(func): + func._artist_property = ArtistPropertyInfo(kwdoc, is_alias) + return func + return decorator + + # In the following check_foo() functions, the first parameter starts with an # underscore because it is intended to be positional-only (e.g., so that # `_api.check_isinstance([...], types=foo)` doesn't fail. @@ -261,6 +271,8 @@ def method(self, *args, **kwargs): method = make_alias(prefix + prop) method.__name__ = prefix + alias method.__doc__ = "Alias for `{}`.".format(prefix + prop) + method._artist_property = \ + ArtistPropertyInfo(kwdoc=None, is_alias=True) setattr(cls, prefix + alias, method) if not exists: raise ValueError( diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index 1f33b9d3ec11..b66b862854e2 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -1490,7 +1490,12 @@ def is_alias(self, o): ds = inspect.getdoc(o) if ds is None: return False - return ds.startswith('Alias for ') + result = ds.startswith('Alias for ') + alt_result = (o._artist_property.is_alias + if hasattr(o, '_artist_property') + else False) + assert result == alt_result + return result def aliased_name(self, s): """ diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 4aac1f055db7..efc1f05c2713 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -1304,6 +1304,7 @@ def get_parse_math(self): """Return whether mathtext parsing is considered for this `Text`.""" return self._parse_math + @_api.artist_property(is_alias=True) def set_fontname(self, fontname): """ Alias for `set_family`.