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

Skip to content

Commit ea9f904

Browse files
committed
Proof of concept for adding kwdoc content to properties using a decorator
1 parent 037fcca commit ea9f904

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

lib/matplotlib/_docstring.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,28 @@
33
from . import _api
44

55

6+
def kwdoc(text):
7+
"""
8+
Decorator for adding kwdoc documentation to Artist property setters.
9+
10+
The given text is stored in a privat variable ``_kwdoc`` on the method.
11+
It is used for generating the kwdoc list for artists, which we
12+
auto-generate through docstring interpolation, e.g. via
13+
``%(Line2D:kwdoc)s``.
14+
15+
The text should contain the supported types as well as the default value
16+
if applicable, e.g.:
17+
18+
@_docstring.kwdoc("bool, default: :rc:`text.usetex`")
19+
def set_usetex(self, usetex):
20+
21+
"""
22+
def decorator(func):
23+
func._kwdoc = text
24+
return func
25+
return decorator
26+
27+
628
class Substitution:
729
"""
830
A decorator that performs %-substitution on an object's docstring.

lib/matplotlib/artist.py

Lines changed: 3 additions & 0 deletions
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, '_kwdoc'):
1437+
return func._kwdoc
1438+
14361439
docstring = inspect.getdoc(func)
14371440
if docstring is None:
14381441
return 'unknown'

lib/matplotlib/text.py

Lines changed: 1 addition & 0 deletions
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.kwdoc("bool, default: :rc:`text.usetex`")
12821283
def set_usetex(self, usetex):
12831284
"""
12841285
Parameters

0 commit comments

Comments
 (0)