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

Skip to content

Commit c83d6ac

Browse files
committed
Deduplicate inherited docstrings.
Since Py3.5, inspect.getdoc inherits method docstrings from super-methods (pydoc, sphinx, and IPython's ? do the same). Take advantage of this to deduplicate some docstrings that were already defined for the Artist base methods. Note that Text.set_clip_path's docstring had actually not been updated when we updated the docstring of Artist.set_clip_path... We could add a decorator to check that the docstring is *actually* getting inherited but that seems totally overkill.
1 parent 8d66b47 commit c83d6ac

File tree

4 files changed

+12
-45
lines changed

4 files changed

+12
-45
lines changed

lib/matplotlib/artist.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ def get_aliases(self):
11911191
if not self.is_alias(func):
11921192
continue
11931193
propname = re.search("`({}.*)`".format(name[:4]), # get_.*/set_.*
1194-
func.__doc__).group(1)
1194+
inspect.getdoc(func)).group(1)
11951195
aliases.setdefault(propname, set()).add(name[4:])
11961196
return aliases
11971197

@@ -1213,7 +1213,7 @@ def get_valid_values(self, attr):
12131213
raise AttributeError('%s has no function %s' % (self.o, name))
12141214
func = getattr(self.o, name)
12151215

1216-
docstring = func.__doc__
1216+
docstring = inspect.getdoc(func)
12171217
if docstring is None:
12181218
return 'unknown'
12191219

@@ -1229,7 +1229,7 @@ def get_valid_values(self, attr):
12291229
param_name = func.__code__.co_varnames[1]
12301230
# We could set the presence * based on whether the parameter is a
12311231
# varargs (it can't be a varkwargs) but it's not really worth the it.
1232-
match = re.search("(?m)^ *\*?{} : (.+)".format(param_name), docstring)
1232+
match = re.search(r"(?m)^ *\*?{} : (.+)".format(param_name), docstring)
12331233
if match:
12341234
return match.group(1)
12351235

@@ -1279,7 +1279,7 @@ def get_setters(self):
12791279

12801280
def is_alias(self, o):
12811281
"""Return whether method object *o* is an alias for another method."""
1282-
ds = o.__doc__
1282+
ds = inspect.getdoc(o)
12831283
if ds is None:
12841284
return False
12851285
return ds.startswith('Alias for ')

lib/matplotlib/axis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1659,7 +1659,7 @@ def set_pickradius(self, pickradius):
16591659
self.pickradius = pickradius
16601660

16611661
def set_ticklabels(self, ticklabels, *args, minor=False, **kwargs):
1662-
"""
1662+
r"""
16631663
Set the text values of the tick labels.
16641664
16651665
Parameters

lib/matplotlib/tests/test_artist.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ def test_None_zorder():
258258

259259
@pytest.mark.parametrize('accept_clause, expected', [
260260
('', 'unknown'),
261-
("ACCEPTS: [ '-' | '--' | '-.' ]", "[ '-' | '--' | '-.' ] "),
262-
('ACCEPTS: Some description.', 'Some description. '),
263-
('.. ACCEPTS: Some description.', 'Some description. '),
261+
("ACCEPTS: [ '-' | '--' | '-.' ]", "[ '-' | '--' | '-.' ]"),
262+
('ACCEPTS: Some description.', 'Some description.'),
263+
('.. ACCEPTS: Some description.', 'Some description.'),
264264
('arg : int', 'int'),
265265
('*arg : int', 'int'),
266266
('arg : int\nACCEPTS: Something else.', 'Something else. '),

lib/matplotlib/text.py

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -542,50 +542,17 @@ def _update_clip_properties(self):
542542
bbox = self._bbox_patch.update(clipprops)
543543

544544
def set_clip_box(self, clipbox):
545-
"""
546-
Set the artist's clip `~.transforms.Bbox`.
547-
548-
Parameters
549-
----------
550-
clipbox : `matplotlib.transforms.Bbox`
551-
"""
545+
# docstring inherited.
552546
super().set_clip_box(clipbox)
553547
self._update_clip_properties()
554548

555549
def set_clip_path(self, path, transform=None):
556-
"""
557-
Set the artist's clip path, which may be:
558-
559-
* a `~matplotlib.patches.Patch` (or subclass) instance
560-
561-
* a `~matplotlib.path.Path` instance, in which case
562-
an optional `~matplotlib.transforms.Transform`
563-
instance may be provided, which will be applied to the
564-
path before using it for clipping.
565-
566-
* *None*, to remove the clipping path
567-
568-
For efficiency, if the path happens to be an axis-aligned
569-
rectangle, this method will set the clipping box to the
570-
corresponding rectangle and set the clipping path to *None*.
571-
572-
ACCEPTS: { (`.path.Path`, `.transforms.Transform`),
573-
`.patches.Patch`, None }
574-
"""
550+
# docstring inherited.
575551
super().set_clip_path(path, transform)
576552
self._update_clip_properties()
577553

578554
def set_clip_on(self, b):
579-
"""
580-
Set whether artist uses clipping.
581-
582-
When False, artists will be visible outside of the axes, which can lead
583-
to unexpected results.
584-
585-
Parameters
586-
----------
587-
b : bool
588-
"""
555+
# docstring inherited.
589556
super().set_clip_on(b)
590557
self._update_clip_properties()
591558

@@ -1261,7 +1228,7 @@ def get_usetex(self):
12611228

12621229
def set_fontname(self, fontname):
12631230
"""
1264-
Alias for `.set_family`.
1231+
Alias for `set_family`.
12651232
12661233
One-way alias only: the getter differs.
12671234

0 commit comments

Comments
 (0)