8000 Error out when unsupported kwargs are passed to Scale. · matplotlib/matplotlib@179a3cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 179a3cd

Browse files
committed
Error out when unsupported kwargs are passed to Scale.
No deprecation period, both because 6357245 likewise added the exception for LogScale without deprecation, and because this is by far most likely to be catching bugs rather than real uses.
1 parent 520b5f6 commit 179a3cd

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
API changes
2+
```````````
3+
4+
Passing unsupported keyword arguments to `.ScaleBase` and its subclasses
5+
`.LinearScale`, `.LogScale`, and `.SymLogScale` now raises a TypeError.

lib/matplotlib/scale.py

Lines changed: 10 additions & 14 deletions
< 8000 /tr>
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ScaleBase:
3939
4040
"""
4141

42-
def __init__(self, axis, **kwargs):
42+
def __init__(self, axis):
4343
r"""
4444
Construct a new scale.
4545
@@ -143,8 +143,7 @@ def forward(values: array-like) -> array-like
143143
self._forward = forward
144144
self._inverse = inverse
145145
else:
146-
raise ValueError('arguments to FuncTransform must '
147-
'be functions')
146+
raise ValueError('arguments to FuncTransform must be functions')
148147

149148
def transform_non_affine(self, values):
150149
return self._forward(values)
@@ -382,16 +381,14 @@ def __init__(self, axis, **kwargs):
382381
nonpos = kwargs.pop('nonposy', 'clip')
383382
cbook._check_in_list(['mask', 'clip'], nonposy=nonpos)
384383

385-
if len(kwargs):
386-
raise ValueError(("provided too many kwargs, can only pass "
387-
"{'basex', 'subsx', nonposx'} or "
388-
"{'basey', 'subsy', nonposy'}. You passed ") +
389-
"{!r}".format(kwargs))
384+
if kwargs:
385+
raise TypeError(f"LogScale got an unexpected keyword "
386+
f"argument {next(iter(kwargs))!r}")
390387

391388
if base <= 0 or base == 1:
392389
raise ValueError('The log base cannot be <= 0 or == 1')
393390

394-
self._transform = self.LogTransform(base, nonpos)
391+
self._transform = LogTransform(base, nonpos)
395392
self.subs = subs
396393

397394
@property
@@ -566,18 +563,17 @@ def __init__(self, axis, **kwargs):
566563
linthresh = kwargs.pop('linthreshy', 2.0)
567564
subs = kwargs.pop('subsy', None)
568565
linscale = kwargs.pop('linscaley', 1.0)
569-
566+
if kwargs:
567+
raise TypeError(f"SymmetricalLogScale got an unexpected keyword "
568+
f"argument {next(iter(kwargs))!r}")
570569
if base <= 1.0:
571570
raise ValueError("'basex/basey' must be larger than 1")
572571
if linthresh <= 0.0:
573572
raise ValueError("'linthreshx/linthreshy' must be positive")
574573
if linscale <= 0.0:
575574
raise ValueError("'linscalex/linthreshy' must be positive")
576575

577-
self._transform = self.SymmetricalLogTransform(base,
578-
linthresh,
579-
linscale)
580-
576+
self._transform = SymmetricalLogTransform(base, linthresh, linscale)
581577
self.base = base
582578
self.linthresh = linthresh
583579
self.linscale = linscale

lib/matplotlib/tests/test_scale.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,12 @@ def test_logscale_mask():
108108

109109
def test_extra_kwargs_raise():
110110
fig, ax = plt.subplots()
111-
with pytest.raises(ValueError):
111+
with pytest.raises(TypeError):
112+
ax.set_yscale('linear', nonpos='mask')
113+
with pytest.raises(TypeError):
112114
ax.set_yscale('log', nonpos='mask')
115+
with pytest.raises(TypeError):
116+
ax.set_yscale('symlog', nonpos='mask')
113117

114118

115119
def test_logscale_invert_transform():

0 commit comments

Comments
 (0)
0