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

Skip to content

Commit 23d3d30

Browse files
authored
Merge pull request #18095 from dstansby/scale-kwargs-remove
Error on unexpected kwargs in scale classes
2 parents 524172f + 3378baa commit 23d3d30

File tree

3 files changed

+12
-31
lines changed

3 files changed

+12
-31
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
`~matplotlib.scale` keyword arguments
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
`.scale.ScaleBase`, `.scale.LinearScale` and `.scale.SymmetricalLogScale`
4+
now error if any unexpected keyword arguments are passed to their
5+
constructors.

lib/matplotlib/scale.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
NullLocator, LogLocator, AutoLocator, AutoMinorLocator,
2121
SymmetricalLogLocator, LogitLocator)
2222
from matplotlib.transforms import Transform, IdentityTransform
23-
from matplotlib.cbook import warn_deprecated
2423

2524

2625
class ScaleBase:
@@ -41,7 +40,7 @@ class ScaleBase:
4140
4241
"""
4342

44-
def __init__(self, axis, **kwargs):
43+
def __init__(self, axis):
4544
r"""
4645
Construct a new scale.
4746
@@ -54,14 +53,6 @@ def __init__(self, axis, **kwargs):
5453
be used: a single scale object should be usable by multiple
5554
`~matplotlib.axis.Axis`\es at the same time.
5655
"""
57-
if kwargs:
58-
warn_deprecated(
59-
'3.2', removal='3.4',
60-
message=(
61-
f"ScaleBase got an unexpected keyword argument "
62-
f"{next(iter(kwargs))!r}. This will become an error "
63-
"%(removal)s.")
64-
)
6556

6657
def get_transform(self):
6758
"""
@@ -95,13 +86,12 @@ class LinearScale(ScaleBase):
9586

9687
name = 'linear'
9788

98-
def __init__(self, axis, **kwargs):
89+
def __init__(self, axis):
9990
# This method is present only to prevent inheritance of the base class'
10091
# constructor docstring, which would otherwise end up interpolated into
10192
# the docstring of Axis.set_scale.
10293
"""
10394
"""
104-
super().__init__(axis, **kwargs)
10595

10696
def set_default_locators_and_formatters(self, axis):
10797
# docstring inherited
@@ -480,15 +470,7 @@ def __init__(self, axis, **kwargs):
480470
@cbook._rename_parameter("3.3", f"linthresh{axis_name}", "linthresh")
481471
@cbook._rename_parameter("3.3", f"subs{axis_name}", "subs")
482472
@cbook._rename_parameter("3.3", f"linscale{axis_name}", "linscale")
483-
def __init__(*, base=10, linthresh=2, subs=None, linscale=1, **kwargs):
484-
if kwargs:
485-
warn_deprecated(
486-
'3.2', removal='3.4',
487-
message=(
488-
f"SymmetricalLogScale got an unexpected keyword "
489-
f"argument {next(iter(kwargs))!r}. This will become "
490-
"an error %(removal)s.")
491-
)
473+
def __init__(*, base=10, linthresh=2, subs=None, linscale=1):
492474
return base, linthresh, subs, linscale
493475

494476
base, linthresh, subs, linscale = __init__(**kwargs)

lib/matplotlib/tests/test_scale.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from matplotlib.cbook import MatplotlibDeprecationWarning
21
import matplotlib.pyplot as plt
32
from matplotlib.scale import (
43
LogTransform, InvertedLogTransform,
@@ -106,17 +105,12 @@ def test_logscale_mask():
106105
ax.set(yscale="log")
107106

108107

109-
def test_extra_kwargs_raise_or_warn():
108+
def test_extra_kwargs_raise():
110109
fig, ax = plt.subplots()
111110

112-
with pytest.warns(MatplotlibDeprecationWarning):
113-
ax.set_yscale('linear', foo='mask')
114-
115-
with pytest.raises(TypeError):
116-
ax.set_yscale('log', foo='mask')
117-
118-
with pytest.warns(MatplotlibDeprecationWarning):
119-
ax.set_yscale('symlog', foo='mask')
111+
for scale in ['linear', 'log', 'symlog']:
112+
with pytest.raises(TypeError):
113+
ax.set_yscale(scale, foo='mask')
120114

121115

122116
def test_logscale_invert_transform():

0 commit comments

Comments
 (0)