Skip to content

changed paths in kwdocs #11443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ def mouseover(self, val):

class ArtistInspector(object):
"""
A helper class to inspect an :class:`~matplotlib.artist.Artist` and return
A helper class to inspect an `~matplotlib.artist.Artist` and return
information about its settable properties and their current values.
"""

Expand Down Expand Up @@ -1146,9 +1146,23 @@ def _get_setters_and_targets(self):
if name in cls.__dict__:
source_class = cls.__module__ + "." + cls.__name__
break
source_class = self._replace_path(source_class)
setters.append((name[4:], source_class + "." + name))
return setters

def _replace_path(self, source_class):
"""
Changes the full path to the public API path that is used
in sphinx. This is needed for links to work.
"""

replace_dict = {'_base._AxesBase': 'Axes',
'_axes.Axes': 'Axes'}

for key, value in replace_dict.items():
source_class = source_class.replace(key, value)
return source_class

def get_setters(self):
"""
Get the attribute strings with setters for object. e.g., for a line,
Expand Down Expand Up @@ -1443,12 +1457,32 @@ def setp(obj, *args, **kwargs):
return list(cbook.flatten(ret))


def kwdoc(a):
def kwdoc(artist):
"""
Inspect an `~matplotlib.artist.Artist` class and return
information about its settable properties and their current values.

It use the class `.ArtistInspector`.

Parameters
----------
artist : `~matplotlib.artist.Artist` or an iterable of `Artist`\s

Returns
-------
string
Returns a string with a list or rst table with the settable properties
of the *artist*. The formating depends on the value of
:rc:`docstring.hardcopy`. False result in a list that is intended for
easy reading as a docstring and True result in a rst table intended
for rendering the documentation with sphinx.
"""
hardcopy = matplotlib.rcParams['docstring.hardcopy']
if hardcopy:
return '\n'.join(ArtistInspector(a).pprint_setters_rest(
return '\n'.join(ArtistInspector(artist).pprint_setters_rest(
leadingspace=4))
else:
return '\n'.join(ArtistInspector(a).pprint_setters(leadingspace=2))
return '\n'.join(ArtistInspector(artist).pprint_setters(
leadingspace=2))

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