From 79189ce212aa86456b12e3ed52918c63cf55a878 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 31 Mar 2022 23:59:31 +0200 Subject: [PATCH] Mark artist property aliases explicitly --- lib/matplotlib/_api/__init__.py | 14 +++++++++++++- lib/matplotlib/artist.py | 7 ++++++- lib/matplotlib/text.py | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) 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`.