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

Skip to content

Commit 4e921b0

Browse files
committed
API: deprecation cycle for extra kwargs to linear and symlog scales
While log scale became strict about extra kwargs in a patch release in 6357245 (by @tacaswell), I now think that was a mistake. We do want to get to all of the scales raising on unexpected kwargs so deprecate them in 3.2 to raise in 3.3.
1 parent 179a3cd commit 4e921b0

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

doc/api/next_api_changes/2019-07-24-AL.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ API changes
22
```````````
33

44
Passing unsupported keyword arguments to `.ScaleBase` and its subclasses
5-
`.LinearScale`, `.LogScale`, and `.SymLogScale` now raises a TypeError.
5+
`.LinearScale`, and `.SymLogScale` is deprecated and will raise a `TypeError` in 3.3.
6+
7+
If extra kwargs are pased to `.LogScale`, `TypeError` will now be
8+
raised instead of `ValueError`.

lib/matplotlib/scale.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
NullLocator, LogLocator, AutoLocator, AutoMinorLocator,
2020
SymmetricalLogLocator, LogitLocator)
2121
from matplotlib.transforms import Transform, IdentityTransform
22-
22+
from matplotlib.cbook import warn_deprecated
2323

2424
class ScaleBase:
2525
"""
@@ -39,7 +39,7 @@ class ScaleBase:
3939
4040
"""
4141

42-
def __init__(self, axis):
42+
def __init__(self, axis, **kwargs):
4343
r"""
4444
Construct a new scale.
4545
@@ -52,6 +52,14 @@ def __init__(self, axis):
5252
be used: a single scale object should be usable by multiple
5353
`~matplotlib.axis.Axis`\es at the same time.
5454
"""
55+
if kwargs:
56+
warn_deprecated(
57+
'3.2.0',
58+
message=(
59+
f"ScaleBase got an unexpected keyword "
60+
f"argument {next(iter(kwargs))!r}. "
61+
'In the future this will raise TypeError')
62+
)
5563

5664
def get_transform(self):
5765
"""
@@ -564,8 +572,16 @@ def __init__(self, axis, **kwargs):
564572
subs = kwargs.pop('subsy', None)
565573
linscale = kwargs.pop('linscaley', 1.0)
566574
if kwargs:
567-
raise TypeError(f"SymmetricalLogScale got an unexpected keyword "
568-
f"argument {next(iter(kwargs))!r}")
575+
warn_deprecated(
576+
'3.2.0',
577+
message=(
578+
f"SymmetricalLogScale got an unexpected keyword "
579+
f"argument {next(iter(kwargs))!r}. "
580+
'In the future this will raise TypeError')
581+
)
582+
# raise TypeError(f"SymmetricalLogScale got an unexpected keyword "
583+
# f"argument {next(iter(kwargs))!r}")
584+
569585
if base <= 1.0:
570586
raise ValueError("'basex/basey' must be larger than 1")
571587
if linthresh <= 0.0:

lib/matplotlib/tests/test_scale.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,18 @@ def test_logscale_mask():
106106
ax.set(yscale="log")
107107

108108

109-
def test_extra_kwargs_raise():
109+
def test_extra_kwargs_raise_or_warn():
110110
fig, ax = plt.subplots()
111-
with pytest.raises(TypeError):
111+
112+
# with pytest.raises(TypeError):
113+
with pytest.warns(MatplotlibDeprecationWarning):
112114
ax.set_yscale('linear', nonpos='mask')
115+
113116
with pytest.raises(TypeError):
114117
ax.set_yscale('log', nonpos='mask')
115-
with pytest.raises(TypeError):
118+
119+
# with pytest.raises(TypeError):
120+
with pytest.warns(MatplotlibDeprecationWarning):
116121
ax.set_yscale('symlog', nonpos='mask')
117122

118123

0 commit comments

Comments
 (0)