8000 Use _api.nargs_error in more places · matplotlib/matplotlib@32e3dd5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 32e3dd5

Browse files
committed
Use _api.nargs_error in more places
1 parent 5ce21e3 commit 32e3dd5

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def legend(self, *args, **kwargs):
314314
*args,
315315
**kwargs)
316316
if len(extra_args):
317-
raise TypeError('legend only accepts two non-keyword arguments')
317+
_api.nargs_error('legend', '0-2', len(args))
318318
self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)
319319
self.legend_._remove_method = self._remove_legend
320320
return self.legend_
@@ -2970,8 +2970,7 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
29702970
which inspired this method.
29712971
"""
29722972
if not 1 <= len(args) <= 3:
2973-
raise TypeError('stem expected between 1 or 3 positional '
2974-
f'arguments, got {args}')
2973+
_api.nargs_error('stem', '1-3', len(args))
29752974
_api.check_in_list(['horizontal', 'vertical'], orientation=orientation)
29762975

29772976
if len(args) == 1:
@@ -6383,7 +6382,7 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
63836382
else:
63846383
raise TypeError("arguments do not match valid signatures")
63856384
else:
6386-
raise TypeError("need 1 argument or 3 arguments")
6385+
_api.nargs_error('pcolorfast', '1 or 3', len(args))
63876386

63886387
if style == "quadmesh":
63896388
# data point in each cell is value at lower left corner

lib/matplotlib/legend.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,11 +1352,8 @@ def _parse_legend_args(axs, *args, handles=None, labels=None, **kwargs):
13521352

13531353
# Two arguments:
13541354
# * user defined handles and labels
1355-
elif len(args) >= 2:
1355+
else:
13561356
handles, labels = args[:2]
13571357
extra_args = args[2:]
13581358

1359-
else:
1360-
raise TypeError('Invalid arguments to legend.')
1361-
13621359
return handles, labels, extra_args, kwargs

lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ def cycler(*args, **kwargs):
693693
elif len(args) == 2:
694694
pairs = [(args[0], args[1])]
695695
elif len(args) > 2:
696-
raise TypeError("No more than 2 positional arguments allowed")
696+
_api.nargs_error('cycler', '0-2', len(args))
697697
else:
698698
pairs = kwargs.items()
699699

0 commit comments

Comments
 (0)
0