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

Skip to content

Commit 2795d83

Browse files
committed
Proof of concept for adding kwdoc content to properties using a decorator
1 parent 6b2d3f2 commit 2795d83

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

lib/matplotlib/_docstring.py

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

55

6+
def artist_property(kwdoc):
7+
"""
8+
Decorator to be applied 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.
12+
"""
13+
def decorator(func):
14+
func._kwdoc = kwdoc
15+
return func
16+
return decorator
17+
18+
619
class Substitution:
720
"""
821
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
@@ -1268,6 +1268,7 @@ def set_fontproperties(self, fp):
12681268
self._fontproperties = FontProperties._from_any(fp).copy()
12691269
self.stale = True
12701270

1271+
@_docstring.artist_property(kwdoc="bool, default: :rc:`text.usetex`")
12711272
def set_usetex(self, usetex):
12721273
"""
12731274
Parameters

0 commit comments

Comments
 (0)