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

Appearance settings

Commit 075c5bc

Browse filesBrowse files
authored
Merge pull request #22699 from timhoffm/artist-property-decorator
Proof of concept for adding kwdoc content to properties using a decorator
2 parents 7412ef8 + aaf53c9 commit 075c5bc
Copy full SHA for 075c5bc

File tree

Expand file treeCollapse file tree

4 files changed

+35
-0
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+35
-0
lines changed

‎lib/matplotlib/_docstring.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_docstring.py
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,34 @@
33
from . import _api
44

55

6+
def kwarg_doc(text):
7+
"""
8+
Decorator for defining the kwdoc documentation of artist properties.
9+
10+
This decorator can be applied to artist property setter methods.
11+
The given text is stored in a privat attribute ``_kwarg_doc`` on
12+
the method. It is used to overwrite auto-generated documentation
13+
in the *kwdoc list* for artists. The kwdoc list is used to document
14+
``**kwargs`` when they are properties of an artist. See e.g. the
15+
``**kwargs`` section in `.Axes.text`.
16+
17+
The text should contain the supported types as well as the default value
18+
if applicable, e.g.:
19+
20+
@_docstring.kwarg_doc("bool, default: :rc:`text.usetex`")
21+
def set_usetex(self, usetex):
22+
23+
See Also
24+
--------
25+
matplotlib.artist.kwdoc
26+
27+
"""
28+
def decorator(func):
29+
func._kwarg_doc = text
30+
return func
31+
return decorator
32+
33+
634
class Substitution:
735
"""
836
A decorator that performs %-substitution on an object's docstring.

‎lib/matplotlib/_docstring.pyi

Copy file name to clipboardExpand all lines: lib/matplotlib/_docstring.pyi
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ from typing import Any, Callable, TypeVar, overload
44
_T = TypeVar('_T')
55

66

7+
def kwarg_doc(text: str) -> Callable[[_T], _T]: ...
8+
9+
710
class Substitution:
811
@overload
912
def __init__(self, *args: str): ...

‎lib/matplotlib/artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/artist.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,9 @@ def get_valid_values(self, attr):
14821482
raise AttributeError(f'{self.o} has no function {name}')
14831483
func = getattr(self.o, name)
14841484

1485+
if hasattr(func, '_kwarg_doc'):
1486+
return func._kwarg_doc
1487+
14851488
docstring = inspect.getdoc(func)
14861489
if docstring is None:
14871490
return 'unknown'

‎lib/matplotlib/text.py

Copy file name to clipboardExpand all lines: lib/matplotlib/text.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,7 @@ def set_fontproperties(self, fp):
13141314
self._fontproperties = FontProperties._from_any(fp).copy()
13151315
self.stale = True
13161316

1317+
@_docstring.kwarg_doc("bool, default: :rc:`text.usetex`")
13171318
def set_usetex(self, usetex):
13181319
"""
13191320
Parameters

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.