Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit df7661b

Browse filesBrowse files
committed
Use more kwonly arguments, less manual kwargs-popping.
1 parent db55918 commit df7661b
Copy full SHA for df7661b

File tree

Expand file treeCollapse file tree

8 files changed

+39
-58
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+39
-58
lines changed

‎lib/matplotlib/artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/artist.py
+5-10Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ def getp(obj, property=None):
15071507
get = getp
15081508

15091509

1510-
def setp(obj, *args, **kwargs):
1510+
def setp(obj, *args, file=None, **kwargs):
15111511
"""
15121512
Set a property on an artist object.
15131513
@@ -1531,8 +1531,8 @@ def setp(obj, *args, **kwargs):
15311531
>>> setp(line)
15321532
... long output listing omitted
15331533
1534-
You may specify another output file to `setp` if `sys.stdout` is not
1535-
acceptable for some reason using the *file* keyword-only argument::
1534+
By default `setp` prints to `sys.stdout`, but this can be modified using
1535+
the *file* keyword-only argument::
15361536
15371537
>>> with fopen('output.log') as f:
15381538
>>> setp(line, file=f)
@@ -1567,16 +1567,11 @@ def setp(obj, *args, **kwargs):
15671567

15681568
insp = ArtistInspector(objs[0])
15691569

1570-
# file has to be popped before checking if kwargs is empty
1571-
printArgs = {}
1572-
if 'file' in kwargs:
1573-
printArgs['file'] = kwargs.pop('file')
1574-
15751570
if not kwargs and len(args) < 2:
15761571
if args:
1577-
print(insp.pprint_setters(prop=args[0]), **printArgs)
1572+
print(insp.pprint_setters(prop=args[0]), file=file)
15781573
else:
1579-
print('\n'.join(insp.pprint_setters()), **printArgs)
1574+
print('\n'.join(insp.pprint_setters()), file=file)
15801575
return
15811576

15821577
if len(args) % 2:

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ def inset_axes(self, bounds, *, transform=None, zorder=5, **kwargs):
430430
parent axes.
431431
432432
**kwargs
433-
Other keyword arguments are passed on to the `.Axes` child axes.
433+
Other keyword arguments are passed on to the child `.Axes`.
434434
435435
Returns
436436
-------
@@ -451,14 +451,13 @@ def inset_axes(self, bounds, *, transform=None, zorder=5, **kwargs):
451451
"""
452452
if transform is None:
453453
transform = self.transAxes
454-
label = kwargs.pop('label', 'inset_axes')
454+
kwargs.setdefault('label', 'inset_axes')
455455

456456
# This puts the rectangle into figure-relative coordinates.
457457
inset_locator = _make_inset_locator(bounds, transform, self)
458458
bb = inset_locator(None, None)
459459

460-
inset_ax = Axes(self.figure, bb.bounds, zorder=zorder, label=label,
461-
**kwargs)
460+
inset_ax = Axes(self.figure, bb.bounds, zorder=zorder, **kwargs)
462461
# this locator lets the axes move if in data coordinates.
463462
# it gets called in `ax.apply_aspect() (of all places)
464463
inset_ax.set_axes_locator(inset_locator)
@@ -479,7 +478,6 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
479478
--------
480479
This method is experimental as of 3.0, and the API may change.
481480
482-
483481
Parameters
484482
----------
485483
bounds : [x0, y0, width, height]
@@ -510,7 +508,9 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
510508
4.99, is just below the default level of inset axes.
511509
512510
**kwargs
513-
Other keyword arguments are passed on to the rectangle patch.
511+
Other keyword arguments are passed on to the `.Rectangle` patch:
512+
513+
%(Rectangle)s
514514
515515
Returns
516516
-------
@@ -530,13 +530,13 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
530530

531531
if transform is None:
532532
transform = self.transData
533-
label = kwargs.pop('label', 'indicate_inset')
533+
kwargs.setdefault('label', 'indicate_inset')
534534

535535
x, y, width, height = bounds
536536
rectangle_patch = mpatches.Rectangle(
537537
(x, y), width, height,
538538
facecolor=facecolor, edgecolor=edgecolor, alpha=alpha,
539-
zorder=zorder, label=label, transform=transform, **kwargs)
539+
zorder=zorder, transform=transform, **kwargs)
540540
self.add_patch(rectangle_patch)
541541

542542
connects = []

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def set_prop_cycle(self, *args, **kwargs):
150150
# This should make a copy
151151
self._prop_keys = prop_cycler.keys
152152

153-
def __call__(self, *args, **kwargs):
153+
def __call__(self, *args, data=None, **kwargs):
154154
self.axes._process_unit_info(kwargs=kwargs)
155155

156156
for pos_only in "xy":
@@ -161,9 +161,7 @@ def __call__(self, *args, **kwargs):
161161
if not args:
162162
return
163163

164-
# Process the 'data' kwarg.
165-
data = kwargs.pop("data", None)
166-
if data is not None:
164+
if data is not None: # Process the 'data' kwarg.
167165
replaced = [mpl._replacer(data, arg) for arg in args]
168166
if len(args) == 1:
169167
label_namer_idx = 0
@@ -446,7 +444,7 @@ def __init__(self, fig, rect,
446444
self.set_label(label)
447445
self.set_figure(fig)
448446
self.set_box_aspect(box_aspect)
449-
self.set_axes_locator(kwargs.get("axes_locator", None))
447+
self._axes_locator = None # Optionally set via update(kwargs).
450448

451449
self.spines = self._gen_axes_spines()
452450

‎lib/matplotlib/backend_bases.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_bases.py
+9-10Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,9 +1977,11 @@ def _get_output_canvas(self, backend, fmt):
19771977
"Format {!r} is not supported (supported formats: {})"
19781978
.format(fmt, ", ".join(sorted(self.get_supported_filetypes()))))
19791979

1980-
def print_figure(self, filename, dpi=None, facecolor=None, edgecolor=None,
1981-
orientation='portrait', format=None,
1982-
*, bbox_inches=None, backend=None, **kwargs):
1980+
def print_figure(
1981+
self, filename, dpi=None, facecolor=None, edgecolor=None,
1982+
orientation='portrait', format=None, *,
1983+
bbox_inches=None, pad_inches=None, bbox_extra_artists=None,
1984+
backend=None, **kwargs):
19831985
"""
19841986
Render the figure to hardcopy. Set the figure patch face and edge
19851987
colors. This is useful because some of the GUIs have a gray figure
@@ -2077,14 +2079,11 @@ def print_figure(self, filename, dpi=None, facecolor=None, edgecolor=None,
20772079
print_method, dpi=dpi, orientation=orientation),
20782080
draw_disabled=True)
20792081
self.figure.draw(renderer)
2080-
bbox_artists = kwargs.pop("bbox_extra_artists", None)
20812082
bbox_inches = self.figure.get_tightbbox(
2082-
renderer, bbox_extra_artists=bbox_artists)
2083-
pad = kwargs.pop("pad_inches", None)
2084-
if pad is None:
2085-
pad = rcParams['savefig.pad_inches']
2086-
2087-
bbox_inches = bbox_inches.padded(pad)
2083+
renderer, bbox_extra_artists=bbox_extra_artists)
2084+
if pad_inches is None:
2085+
pad_inches = rcParams['savefig.pad_inches']
2086+
bbox_inches = bbox_inches.padded(pad_inches)
20882087

20892088
# call adjust_bbox to save only the given area
20902089
restore_bbox = tight_bbox.adjust_bbox(self.figure, bbox_inches,

‎lib/matplotlib/backends/backend_cairo.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_cairo.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,8 @@ def print_svg(self, fobj, *args, **kwargs):
436436
def print_svgz(self, fobj, *args, **kwargs):
437437
return self._save(fobj, 'svgz', *args, **kwargs)
438438

439-
def _save(self, fo, fmt, **kwargs):
439+
def _save(self, fo, fmt, *, orientation='portrait', **kwargs):
440440
# save PDF/PS/SVG
441-
orientation = kwargs.get('orientation', 'portrait')
442441

443442
dpi = 72
444443
self.figure.dpi = dpi

‎lib/matplotlib/contour.py

Copy file name to clipboardExpand all lines: lib/matplotlib/contour.py
+11-10Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -727,9 +727,10 @@ class ContourSet(cm.ScalarMappable, ContourLabeler):
727727

728728
def __init__(self, ax, *args,
729729
levels=None, filled=False, linewidths=None, linestyles=None,
730-
alpha=None, origin=None, extent=None,
730+
hatches=(None,), alpha=None, origin=None, extent=None,
731731
cmap=None, colors=None, norm=None, vmin=None, vmax=None,
732-
extend='neither', antialiased=None,
732+
extend='neither', antialiased=None, nchunk=0, locator=None,
733+
transform=None,
733734
**kwargs):
734735
"""
735736
Draw contour lines or filled regions, depending on
@@ -780,7 +781,7 @@ def __init__(self, ax, *args,
780781
self.filled = filled
781782
self.linewidths = linewidths
782783
self.linestyles = linestyles
783-
self.hatches = kwargs.pop('hatches', [None])
784+
self.hatches = hatches
784785
self.alpha = alpha
785786
self.origin = origin
786787
self.extent = extent
@@ -793,8 +794,8 @@ def __init__(self, ax, *args,
793794
# The default for line contours will be taken from the
794795
# LineCollection default, which uses :rc:`lines.antialiased`.
795796

796-
self.nchunk = kwargs.pop('nchunk', 0)
797-
self.locator = kwargs.pop('locator', None)
797+
self.nchunk = nchunk
798+
self.locator = locator
798799
if (isinstance(norm, mcolors.LogNorm)
799800
or isinstance(self.locator, ticker.LogLocator)):
800801
self.logscale = True
@@ -812,7 +813,7 @@ def __init__(self, ax, *args,
812813
if self.origin == 'image':
813814
self.origin = mpl.rcParams['image.origin']
814815

815-
self._transform = kwargs.pop('transform', None)
816+
self._transform = transform
816817

817818
kwargs = self._process_args(*args, **kwargs)
818819
self._process_levels()
@@ -1401,7 +1402,7 @@ class QuadContourSet(ContourSet):
14011402
levels for filled contours. See :meth:`_process_colors` method.
14021403
"""
14031404

1404-
def _process_args(self, *args, **kwargs):
1405+
def _process_args(self, *args, corner_mask=None, **kwargs):
14051406
"""
14061407
Process args and kwargs.
14071408
"""
@@ -1417,9 +1418,9 @@ def _process_args(self, *args, **kwargs):
14171418
else:
14181419
import matplotlib._contour as _contour
14191420

1420-
self._corner_mask = kwargs.pop('corner_mask', None)
1421-
if self._corner_mask is None:
1422-
self._corner_mask = mpl.rcParams['contour.corner_mask']
1421+
if corner_mask is None:
1422+
corner_mask = mpl.rcParams['contour.corner_mask']
1423+
self._corner_mask = corner_mask
14231424

14241425
x, y, z = self._contour_args(args, kwargs)
14251426

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,8 +2164,7 @@ def get_next_color():
21642164
get_next_color_func=get_next_color)
21652165

21662166

2167-
def _params(c=None, xsize=2, **kwargs):
2168-
edgecolors = kwargs.pop('edgecolors', None)
2167+
def _params(c=None, xsize=2, *, edgecolors=None, **kwargs):
21692168
return (c, edgecolors, kwargs if kwargs is not None else {}, xsize)
21702169
_result = namedtuple('_result', 'c, colors')
21712170

‎lib/mpl_toolkits/axisartist/floating_axes.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/axisartist/floating_axes.py
+1-11Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -320,17 +320,7 @@ def __init__(self, *args, **kwargs):
320320
self.adjust_axes_lim()
321321

322322
def _gen_axes_patch(self):
323-
"""
324-
Returns the patch used to draw the background of the axes. It
325-
is also used as the clipping path for any data elements on the
326-
axes.
327-
328-
In the standard axes, this is a rectangle, but in other
329-
projections it may not be.
330-
331-
.. note::
332-
Intended to be overridden by new projection types.
333-
"""
323+
# docstring inherited
334324
grid_helper = self.get_grid_helper()
335325
t = grid_helper.get_boundary()
336326
return mpatches.Polygon(t)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.