Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd8a91ba

Browse files
timhoffmoscargus
authored andcommitted
Proof of concept for adding kwdoc content to properties using a decorator
1 parent61ed3f4 commitd8a91ba

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

‎lib/matplotlib/_docstring.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,31 @@
33
from .import_api
44

55

6+
defkwarg_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+
defdecorator(func):
26+
func._kwarg_doc=text
27+
returnfunc
28+
returndecorator
29+
30+
631
classSubstitution:
732
"""
833
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
@@ -1479,6 +1479,9 @@ def get_valid_values(self, attr):
14791479
raiseAttributeError(f'{self.o} has no function{name}')
14801480
func=getattr(self.o,name)
14811481

1482+
ifhasattr(func,'_kwarg_doc'):
1483+
returnfunc._kwarg_doc
1484+
14821485
docstring=inspect.getdoc(func)
14831486
ifdocstringisNone:
14841487
return'unknown'

‎lib/matplotlib/text.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,7 @@ def set_fontproperties(self, fp):
12821282
self._fontproperties=FontProperties._from_any(fp).copy()
12831283
self.stale=True
12841284

1285+
@_docstring.kwarg_doc("bool, default: :rc:`text.usetex`")
12851286
defset_usetex(self,usetex):
12861287
"""
12871288
Parameters

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp