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

Skip to content

Commit 5e8cf99

Browse files
committed
Simplify/fix some manual manipulation of len(args).
The note removed in contributing.rst is simply not true anymore in Py3. The changes in patches.py fix what appears to have been a bug (well, I'd rather we decide once and for all whether we want to accept `(x, y)` or `((x, y))` but until then we may as well make sure both work -- end of rant).
1 parent abe0e39 commit 5e8cf99

4 files changed

Lines changed: 5 additions & 25 deletions

File tree

doc/devel/contributing.rst

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -410,26 +410,6 @@ local arguments and the rest are passed on as
410410
self.add_line(line)
411411
lines.append(line)
412412

413-
Note: there is a use case when ``kwargs`` are meant to be used locally
414-
in the function (not passed on), but you still need the ``**kwargs``
415-
idiom. That is when you want to use ``*args`` to allow variable
416-
numbers of non-keyword args. In this case, python will not allow you
417-
to use named keyword args after the ``*args`` usage, so you will be
418-
forced to use ``**kwargs``. An example is
419-
:meth:`matplotlib.contour.ContourLabeler.clabel`::
420-
421-
# in contour.py
422-
def clabel(self, *args, **kwargs):
423-
fontsize = kwargs.get('fontsize', None)
424-
inline = kwargs.get('inline', 1)
425-
self.fmt = kwargs.get('fmt', '%1.3f')
426-
colors = kwargs.get('colors', None)
427-
if len(args) == 0:
428-
levels = self.levels
429-
indices = range(len(self.levels))
430-
elif len(args) == 1:
431-
...etc...
432-
433413
.. _using_logging:
434414

435415
Using logging for debug messages

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def __setstate__(self, state):
156156
self.set_prop_cycle()
157157

158158
def set_prop_cycle(self, *args, **kwargs):
159+
# Can't do `args == (None,)` as that crashes cycler.
159160
if not (args or kwargs) or (len(args) == 1 and args[0] is None):
160161
prop_cycler = rcParams['axes.prop_cycle']
161162
else:
@@ -1206,6 +1207,7 @@ def set_prop_cycle(self, *args, **kwargs):
12061207
if args and kwargs:
12071208
raise TypeError("Cannot supply both positional and keyword "
12081209
"arguments to this method.")
1210+
# Can't do `args == (None,)` as that crashes cycler.
12091211
if len(args) == 1 and args[0] is None:
12101212
prop_cycle = None
12111213
else:

lib/matplotlib/patches.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ def set_bounds(self, *args):
775775
776776
ACCEPTS: (left, bottom, width, height)
777777
"""
778-
if len(args) == 0:
778+
if len(args) == 1:
779779
l, b, w, h = args[0]
780780
else:
781781
l, b, w, h = args
@@ -2628,7 +2628,7 @@ def set_bounds(self, *args):
26282628
26292629
ACCEPTS: (left, bottom, width, height)
26302630
"""
2631-
if len(args) == 0:
2631+
if len(args) == 1:
26322632
l, b, w, h = args[0]
26332633
else:
26342634
l, b, w, h = args

lib/matplotlib/tri/triplot.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ def triplot(ax, *args, **kwargs):
4141
x, y, edges = (tri.x, tri.y, tri.edges)
4242

4343
# Decode plot format string, e.g., 'ro-'
44-
fmt = ""
45-
if len(args) > 0:
46-
fmt = args[0]
44+
fmt = args[0] if args else ""
4745
linestyle, marker, color = matplotlib.axes._base._process_plot_format(fmt)
4846

4947
# Insert plot format string into a copy of kwargs (kwargs values prevail).

0 commit comments

Comments
 (0)