Skip to content

Commit b3cb8b0

Browse files
committed
Start replacing ACCEPTS table by parsing numpydoc.
In most cases, we can just look for 'param : type' in the docstring. We let ACCEPTS still have the priority to handle weird cases such as set_xlim where we document the first arg as "bottom", but it's "bottom, top" for the purpose of the ACCEPTS table; resolving *that* problem is punted to later. Only removed a few ACCEPTS entries as a proof of principle.
1 parent 1e6790f commit b3cb8b0

File tree

2 files changed

+22
-47
lines changed

2 files changed

+22
-47
lines changed

lib/matplotlib/artist.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -1054,17 +1054,16 @@ def mouseover(self, val):
10541054

10551055
class ArtistInspector(object):
10561056
"""
1057-
A helper class to inspect an :class:`~matplotlib.artist.Artist`
1058-
and return information about it's settable properties and their
1059-
current values.
1057+
A helper class to inspect an :class:`~matplotlib.artist.Artist` and return
1058+
information about its settable properties and their current values.
10601059
"""
1060+
10611061
def __init__(self, o):
10621062
"""
1063-
Initialize the artist inspector with an
1064-
:class:`~matplotlib.artist.Artist` or iterable of :class:`Artists`.
1065-
If an iterable is used, we assume it is a homogeneous sequence (all
1066-
:class:`Artists` are of the same type) and it is your responsibility
1067-
to make sure this is so.
1063+
Initialize the artist inspector with an `Artist` or an iterable of
1064+
`Artist`\s. If an iterable is used, we assume it is a homogeneous
1065+
sequence (all `Artists` are of the same type) and it is your
1066+
responsibility to make sure this is so.
10681067
"""
10691068
if not isinstance(o, Artist):
10701069
if cbook.iterable(o):
@@ -1135,6 +1134,14 @@ def get_valid_values(self, attr):
11351134
match = self._get_valid_values_regex.search(docstring)
11361135
if match is not None:
11371136
return re.sub("\n *", " ", match.group(1))
1137+
1138+
# Much faster than list(inspect.signature(func).parameters)[1],
1139+
# although barely relevant wrt. matplotlib's total import time.
1140+
param_name = func.__code__.co_varnames[1]
1141+
match = re.search("(?m)^ *{} : (.+)".format(param_name), docstring)
1142+
if match:
1143+
return match.group(1)
1144+
11381145
return 'unknown'
11391146

11401147
def _get_setters_and_targets(self):

lib/matplotlib/axes/_base.py

+7-39
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,6 @@ def set_figure(self, fig):
602602
"""
603603
Set the `.Figure` for this `.Axes`.
604604
605-
.. ACCEPTS: `.Figure`
606-
607605
Parameters
608606
----------
609607
fig : `.Figure`
@@ -907,14 +905,9 @@ def set_axes_locator(self, locator):
907905
"""
908906
Set the axes locator.
909907
910-
.. ACCEPTS: a callable object which takes an axes instance and
911-
renderer and returns a bbox.
912-
913908
Parameters
914909
----------
915-
locator : callable
916-
A locator function, which takes an axes and a renderer and returns
917-
a bbox.
910+
locator : Callable[[Axes, Renderer], Bbox]
918911
"""
919912
self._axes_locator = locator
920913
self.stale = True
@@ -1022,10 +1015,10 @@ def cla(self):
10221015
except TypeError:
10231016
pass
10241017
# update the minor locator for x and y axis based on rcParams
1025-
if (rcParams['xtick.minor.visible']):
1018+
if rcParams['xtick.minor.visible']:
10261019
self.xaxis.set_minor_locator(mticker.AutoMinorLocator())
10271020

1028-
if (rcParams['ytick.minor.visible']):
1021+
if rcParams['ytick.minor.visible']:
10291022
self.yaxis.set_minor_locator(mticker.AutoMinorLocator())
10301023

10311024
if self._sharex is None:
@@ -1125,9 +1118,8 @@ def get_facecolor(self):
11251118
get_fc = get_facecolor
11261119

11271120
def set_facecolor(self, color):
1128-
"""Set the Axes facecolor.
1129-
1130-
.. ACCEPTS: color
1121+
"""
1122+
Set the Axes facecolor.
11311123
11321124
Parameters
11331125
----------
@@ -1314,8 +1306,6 @@ def set_adjustable(self, adjustable, share=False):
13141306
If ``True``, apply the settings to all shared Axes.
13151307
Default is ``False``.
13161308
1317-
.. ACCEPTS: [ 'box' | 'datalim']
1318-
13191309
See Also
13201310
--------
13211311
matplotlib.axes.Axes.set_aspect
@@ -2132,8 +2122,6 @@ def set_autoscale_on(self, b):
21322122
"""
21332123
Set whether autoscaling is applied on plot commands
21342124
2135-
.. ACCEPTS: bool
2136-
21372125
Parameters
21382126
----------
21392127
b : bool
@@ -2145,8 +2133,6 @@ def set_autoscalex_on(self, b):
21452133
"""
21462134
Set whether autoscaling for the x-axis is applied on plot commands
21472135
2148-
.. ACCEPTS: bool
2149-
21502136
Parameters
21512137
----------
21522138
b : bool
@@ -2157,8 +2143,6 @@ def set_autoscaley_on(self, b):
21572143
"""
21582144
Set whether autoscaling for the y-axis is applied on plot commands
21592145
2160-
.. ACCEPTS: bool
2161-
21622146
Parameters
21632147
----------
21642148
b : bool
@@ -2200,8 +2184,6 @@ def set_xmargin(self, m):
22002184
I.e. for a data range [0, 2], a factor of ``m = -0.1`` will result in
22012185
a range [0.2, 1.8].
22022186
2203-
.. ACCEPTS: float greater than -0.5
2204-
22052187
Parameters
22062188
----------
22072189
m : float greater than -0.5
@@ -2224,8 +2206,6 @@ def set_ymargin(self, m):
22242206
I.e. for a data range [0, 2], a factor of ``m = -0.1`` will result in
22252207
a range [0.2, 1.8].
22262208
2227-
.. ACCEPTS: float greater than -0.5
2228-
22292209
Parameters
22302210
----------
22312211
m : float greater than -0.5
@@ -2306,8 +2286,6 @@ def set_rasterization_zorder(self, z):
23062286
z : float or None
23072287
zorder below which artists are rasterized. ``None`` means that
23082288
artists do not get rasterized based on zorder.
2309-
2310-
.. ACCEPTS: float or None
23112289
"""
23122290
self._rasterization_zorder = z
23132291
self.stale = True
@@ -2636,8 +2614,6 @@ def set_frame_on(self, b):
26362614
"""
26372615
Set whether the axes rectangle patch is drawn.
26382616
2639-
.. ACCEPTS: bool
2640-
26412617
Parameters
26422618
----------
26432619
b : bool
@@ -2655,8 +2631,6 @@ def set_axisbelow(self, b):
26552631
"""
26562632
Set whether axis ticks and gridlines are above or below most artists.
26572633
2658-
.. ACCEPTS: [ bool | 'line' ]
2659-
26602634
Parameters
26612635
----------
26622636
b : bool or 'line'
@@ -3268,11 +3242,9 @@ def set_xticklabels(self, labels, fontdict=None, minor=False, **kwargs):
32683242
"""
32693243
Set the x-tick labels with list of string labels.
32703244
3271-
.. ACCEPTS: list of string labels
3272-
32733245
Parameters
32743246
----------
3275-
labels : list of str
3247+
labels : List[str]
32763248
List of string labels.
32773249
32783250
fontdict : dict, optional
@@ -3605,11 +3577,9 @@ def set_yticklabels(self, labels, fontdict=None, minor=False, **kwargs):
36053577
"""
36063578
Set the y-tick labels with list of strings labels.
36073579
3608-
.. ACCEPTS: list of string labels
3609-
36103580
Parameters
36113581
----------
3612-
labels : list of str
3582+
labels : List[str]
36133583
list of string labels
36143584
36153585
fontdict : dict, optional
@@ -3747,8 +3717,6 @@ def set_navigate(self, b):
37473717
"""
37483718
Set whether the axes responds to navigation toolbar commands
37493719
3750-
.. ACCEPTS: bool
3751-
37523720
Parameters
37533721
----------
37543722
b : bool

0 commit comments

Comments
 (0)