Skip to content

Commit 2486f89

Browse files
authored
Merge pull request #11443 from fredrik-1/kwdoc_bug
changed paths in kwdocs
2 parents 5669d1c + 8573544 commit 2486f89

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

lib/matplotlib/artist.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ def mouseover(self, val):
10871087

10881088
class ArtistInspector(object):
10891089
"""
1090-
A helper class to inspect an :class:`~matplotlib.artist.Artist` and return
1090+
A helper class to inspect an `~matplotlib.artist.Artist` and return
10911091
information about its settable properties and their current values.
10921092
"""
10931093

@@ -1198,9 +1198,23 @@ def _get_setters_and_targets(self):
11981198
if name in cls.__dict__:
11991199
source_class = cls.__module__ + "." + cls.__name__
12001200
break
1201+
source_class = self._replace_path(source_class)
12011202
setters.append((name[4:], source_class + "." + name))
12021203
return setters
12031204

1205+
def _replace_path(self, source_class):
1206+
"""
1207+
Changes the full path to the public API path that is used
1208+
in sphinx. This is needed for links to work.
1209+
"""
1210+
1211+
replace_dict = {'_base._AxesBase': 'Axes',
1212+
'_axes.Axes': 'Axes'}
1213+
1214+
for key, value in replace_dict.items():
1215+
source_class = source_class.replace(key, value)
1216+
return source_class
1217+
12041218
def get_setters(self):
12051219
"""
12061220
Get the attribute strings with setters for object. e.g., for a line,
@@ -1495,12 +1509,32 @@ def setp(obj, *args, **kwargs):
14951509
return list(cbook.flatten(ret))
14961510

14971511

1498-
def kwdoc(a):
1512+
def kwdoc(artist):
1513+
"""
1514+
Inspect an `~matplotlib.artist.Artist` class and return
1515+
information about its settable properties and their current values.
1516+
1517+
It use the class `.ArtistInspector`.
1518+
1519+
Parameters
1520+
----------
1521+
artist : `~matplotlib.artist.Artist` or an iterable of `Artist`\s
1522+
1523+
Returns
1524+
-------
1525+
string
1526+
Returns a string with a list or rst table with the settable properties
1527+
of the *artist*. The formating depends on the value of
1528+
:rc:`docstring.hardcopy`. False result in a list that is intended for
1529+
easy reading as a docstring and True result in a rst table intended
1530+
for rendering the documentation with sphinx.
1531+
"""
14991532
hardcopy = matplotlib.rcParams['docstring.hardcopy']
15001533
if hardcopy:
1501-
return '\n'.join(ArtistInspector(a).pprint_setters_rest(
1534+
return '\n'.join(ArtistInspector(artist).pprint_setters_rest(
15021535
leadingspace=4))
15031536
else:
1504-
return '\n'.join(ArtistInspector(a).pprint_setters(leadingspace=2))
1537+
return '\n'.join(ArtistInspector(artist).pprint_setters(
1538+
leadingspace=2))
15051539

15061540
docstring.interpd.update(Artist=kwdoc(Artist))

0 commit comments

Comments
 (0)