Skip to content

Commit ee602b3

Browse files
committed
Proof of concept for adding kwdoc content to properties using a decorator
1 parent bcef5d6 commit ee602b3

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

lib/matplotlib/_docstring.py

+25
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,31 @@
33
from . import _api
44

55

6+
def kwarg_doc(text):
7+
"""
8+
Decorator for defining the documentation used when artist properties are
9+
passed through as keyword arguments.
10+
11+
See e.g. the `**kwargs` section in `.Axes.text`.
12+
13+
The given text is stored in a privat variable ``_kwarg_doc`` on the method.
14+
It is used for generating the kwdoc list for artists, which we
15+
auto-generate through docstring interpolation, e.g. via
16+
``%(Line2D:kwdoc)s``.
17+
18+
The text should contain the supported types as well as the default value
19+
if applicable, e.g.:
20+
21+
@_docstring.kwarg_doc("bool, default: :rc:`text.usetex`")
22+
def set_usetex(self, usetex):
23+
24+
"""
25+
def decorator(func):
26+
func._kwarg_doc = text
27+
return func
28+
return decorator
29+
30+
631
class Substitution:
732
"""
833
A decorator that performs %-substitution on an object's docstring.

lib/matplotlib/artist.py

+3
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,9 @@ def get_valid_values(self, attr):
14331433
raise AttributeError('%s has no function %s' % (self.o, name))
14341434
func = getattr(self.o, name)
14351435

1436+
if hasattr(func, '_kwarg_doc'):
1437+
return func._kwarg_doc
1438+
14361439
docstring = inspect.getdoc(func)
14371440
if docstring is None:
14381441
return 'unknown'

lib/matplotlib/text.py

+1
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,7 @@ def set_fontproperties(self, fp):
12791279
self._fontproperties = FontProperties._from_any(fp).copy()
12801280
self.stale = True
12811281

1282+
@_docstring.kwarg_doc("bool, default: :rc:`text.usetex`")
12821283
def set_usetex(self, usetex):
12831284
"""
12841285
Parameters

0 commit comments

Comments
 (0)