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

Skip to content

Commit dcb7ae7

Browse files
committed
Change manual kwargs popping to kwonly arguments.
Only simple cases (no mutable defaults, no defaults depending on other args) are handled so far.
1 parent be12168 commit dcb7ae7

37 files changed

+187
-306
lines changed

examples/api/custom_scale_example.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class MercatorLatitudeScale(mscale.ScaleBase):
4444
# scale.
4545
name = 'mercator'
4646

47-
def __init__(self, axis, **kwargs):
47+
def __init__(self, axis, *, thresh=np.deg2rad(85), **kwargs):
4848
"""
4949
Any keyword arguments passed to ``set_xscale`` and
5050
``set_yscale`` will be passed along to the scale's
@@ -53,8 +53,7 @@ def __init__(self, axis, **kwargs):
5353
thresh: The degree above which to crop the data.
5454
"""
5555
mscale.ScaleBase.__init__(self)
56-
thresh = kwargs.pop("thresh", np.radians(85))
57-
if thresh >= np.pi / 2.0:
56+
if thresh >= np.pi / 2:
5857
raise ValueError("thresh must be less than pi/2")
5958
self.thresh = thresh
6059

examples/api/radar_chart.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ def __init__(self, *args, **kwargs):
6464
# rotate plot such that the first axis is at the top
6565
self.set_theta_zero_location('N')
6666

67-
def fill(self, *args, **kwargs):
67+
def fill(self, *args, closed=True, **kwargs):
6868
"""Override fill so that line is closed by default"""
69-
closed = kwargs.pop('closed', True)
7069
return super().fill(closed=closed, *args, **kwargs)
7170

7271
def plot(self, *args, **kwargs):

examples/subplots_axes_and_figures/custom_figure_class.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212

1313

1414
class MyFigure(Figure):
15-
def __init__(self, *args, **kwargs):
15+
def __init__(self, *args, figtitle='hi mom', **kwargs):
1616
"""
1717
custom kwarg figtitle is a figure title
1818
"""
19-
figtitle = kwargs.pop('figtitle', 'hi mom')
20-
Figure.__init__(self, *args, **kwargs)
19+
super().__init__(*args, **kwargs)
2120
self.text(0.5, 0.95, figtitle, ha='center')
2221

2322

examples/text_labels_and_annotations/usetex_baseline_test.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,15 @@ class Axes(maxes.Axes):
2020
usetex=False in the same figure. It does not work in the ps backend.
2121
"""
2222

23-
def __init__(self, *kl, **kw):
24-
self.usetex = kw.pop("usetex", "False")
25-
self.preview = kw.pop("preview", "False")
26-
27-
maxes.Axes.__init__(self, *kl, **kw)
23+
def __init__(self, *args, usetex=False, preview=False, **kwargs):
24+
self.usetex = usetex
25+
self.preview = preview
26+
super().__init__(*args, **kwargs)
2827

2928
def draw(self, renderer):
30-
usetex = plt.rcParams["text.usetex"]
31-
preview = plt.rcParams["text.latex.preview"]
32-
plt.rcParams["text.usetex"] = self.usetex
33-
plt.rcParams["text.latex.preview"] = self.preview
34-
35-
maxes.Axes.draw(self, renderer)
36-
37-
plt.rcParams["text.usetex"] = usetex
38-
plt.rcParams["text.latex.preview"] = preview
29+
with plt.rc_context({"text.usetex": self.usetex,
30+
"text.latex.preview": self.preview}):
31+
super().draw(renderer)
3932

4033

4134
subplot = maxes.subplot_class_factory(Axes)

examples/user_interfaces/toolmanager_sgskip.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class GroupHideTool(ToolToggleBase):
5656
description = 'Show by gid'
5757
default_toggled = True
5858

59-
def __init__(self, *args, **kwargs):
60-
self.gid = kwargs.pop('gid')
61-
ToolToggleBase.__init__(self, *args, **kwargs)
59+
def __init__(self, *args, gid, **kwargs):
60+
self.gid = gid
61+
super().__init__(*args, **kwargs)
6262

6363
def enable(self, *args):
6464
self.set_lines_visibility(True)

lib/matplotlib/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ def param(func):
17721772
pass
17731773

17741774
@functools.wraps(func)
1775-
def inner(ax, *args, **kwargs):
1775+
def inner(ax, *args, data=None, **kwargs):
17761776
# this is needed because we want to change these values if
17771777
# arg_names_at_runtime==True, but python does not allow assigning
17781778
# to a variable in a outer scope. So use some new local ones and
@@ -1783,8 +1783,6 @@ def inner(ax, *args, **kwargs):
17831783

17841784
label = None
17851785

1786-
data = kwargs.pop('data', None)
1787-
17881786
if data is None: # data validation
17891787
args = tuple(sanitize_sequence(a) for a in args)
17901788
else:

lib/matplotlib/axes/_axes.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5488,20 +5488,14 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
54885488
return im
54895489

54905490
@staticmethod
5491-
def _pcolorargs(funcname, *args, **kw):
5492-
# This takes one kwarg, allmatch.
5493-
# If allmatch is True, then the incoming X, Y, C must
5494-
# have matching dimensions, taking into account that
5495-
# X and Y can be 1-D rather than 2-D. This perfect
5496-
# match is required for Gouroud shading. For flat
5497-
# shading, X and Y specify boundaries, so we need
5498-
# one more boundary than color in each direction.
5499-
# For convenience, and consistent with Matlab, we
5500-
# discard the last row and/or column of C if necessary
5501-
# to meet this condition. This is done if allmatch
5502-
# is False.
5503-
5504-
allmatch = kw.pop("allmatch", False)
5491+
def _pcolorargs(funcname, *args, allmatch=False):
5492+
# If allmatch is True, then the incoming X, Y, C must have matching
5493+
# dimensions, taking into account that X and Y can be 1-D rather than
5494+
# 2-D. This perfect match is required for Gouroud shading. For flat
5495+
# shading, X and Y specify boundaries, so we need one more boundary
5496+
# than color in each direction. For convenience, and consistent with
5497+
# Matlab, we discard the last row and/or column of C if necessary to
5498+
# meet this condition. This is done if allmatch is False.
55055499

55065500
if len(args) == 1:
55075501
C = np.asanyarray(args[0])
@@ -5548,7 +5542,7 @@ def _pcolorargs(funcname, *args, **kw):
55485542
'Incompatible X, Y inputs to %s; see help(%s)' % (
55495543
funcname, funcname))
55505544
if allmatch:
5551-
if not (Nx == numCols and Ny == numRows):
5545+
if (Nx, Ny) != (numCols, numRows):
55525546
raise TypeError('Dimensions of C %s are incompatible with'
55535547
' X (%d) and/or Y (%d); see help(%s)' % (
55545548
C.shape, Nx, Ny, funcname))

lib/matplotlib/axes/_base.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,7 +2712,8 @@ def grid(self, b=None, which='major', axis='both', **kwargs):
27122712
if axis == 'y' or axis == 'both':
27132713
self.yaxis.grid(b, which=which, **kwargs)
27142714

2715-
def ticklabel_format(self, **kwargs):
2715+
def ticklabel_format(self, *, axis='both', style='', scilimits=None,
2716+
useOffset=None, useLocale=None, useMathText=None):
27162717
"""
27172718
Change the `~matplotlib.ticker.ScalarFormatter` used by
27182719
default for linear axes.
@@ -2722,6 +2723,7 @@ def ticklabel_format(self, **kwargs):
27222723
============== =========================================
27232724
Keyword Description
27242725
============== =========================================
2726+
*axis* [ 'x' | 'y' | 'both' ]
27252727
*style* [ 'sci' (or 'scientific') | 'plain' ]
27262728
plain turns off scientific notation
27272729
*scilimits* (m, n), pair of integers; if *style*
@@ -2734,7 +2736,6 @@ def ticklabel_format(self, **kwargs):
27342736
if False, no offset will be used; if a
27352737
numeric offset is specified, it will be
27362738
used.
2737-
*axis* [ 'x' | 'y' | 'both' ]
27382739
*useLocale* If True, format the number according to
27392740
the current locale. This affects things
27402741
such as the character used for the
@@ -2753,12 +2754,8 @@ def ticklabel_format(self, **kwargs):
27532754
:exc:`AttributeError` will be raised.
27542755
27552756
"""
2756-
style = kwargs.pop('style', '').lower()
2757-
scilimits = kwargs.pop('scilimits', None)
2758-
useOffset = kwargs.pop('useOffset', None)
2759-
useLocale = kwargs.pop('useLocale', None)
2760-
useMathText = kwargs.pop('useMathText', None)
2761-
axis = kwargs.pop('axis', 'both').lower()
2757+
style = style.lower()
2758+
axis = axis.lower()
27622759
if scilimits is not None:
27632760
try:
27642761
m, n = scilimits

lib/matplotlib/axis.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ def set_pickradius(self, pickradius):
16121612
"""
16131613
self.pickradius = pickradius
16141614

1615-
def set_ticklabels(self, ticklabels, *args, **kwargs):
1615+
def set_ticklabels(self, ticklabels, *args, minor=False, **kwargs):
16161616
"""
16171617
Set the text values of the tick labels. Return a list of Text
16181618
instances. Use *kwarg* *minor=True* to select minor ticks.
@@ -1641,7 +1641,6 @@ def set_ticklabels(self, ticklabels, *args, **kwargs):
16411641
# replace the ticklabels list with the processed one
16421642
ticklabels = get_labels
16431643

1644-
minor = kwargs.pop('minor', False)
16451644
if minor:
16461645
self.set_minor_formatter(mticker.FixedFormatter(ticklabels))
16471646
ticks = self.get_minor_ticks()

lib/matplotlib/backends/backend_agg.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ def print_to_buffer(self):
541541

542542
if _has_pil:
543543
# add JPEG support
544-
def print_jpg(self, filename_or_obj, *args, **kwargs):
544+
def print_jpg(self, filename_or_obj, *args, dryrun=False, **kwargs):
545545
"""
546546
Other Parameters
547547
----------------
@@ -562,7 +562,7 @@ def print_jpg(self, filename_or_obj, *args, **kwargs):
562562
should be stored as a progressive JPEG file.
563563
"""
564564
buf, size = self.print_to_buffer()
565-
if kwargs.pop("dryrun", False):
565+
if dryrun:
566566
return
567567
# The image is "pasted" onto a white background image to safely
568568
# handle any transparency
@@ -583,9 +583,9 @@ def print_jpg(self, filename_or_obj, *args, **kwargs):
583583
print_jpeg = print_jpg
584584

585585
# add TIFF support
586-
def print_tif(self, filename_or_obj, *args, **kwargs):
586+
def print_tif(self, filename_or_obj, *args, dryrun=False, **kwargs):
587587
buf, size = self.print_to_buffer()
588-
if kwargs.pop("dryrun", False):
588+
if dryrun:
589589
return
590590
image = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1)
591591
dpi = (self.figure.dpi, self.figure.dpi)

0 commit comments

Comments
 (0)