8000 Simplify parameter handling in FloatingAxesBase. · matplotlib/matplotlib@48d6fda · GitHub
[go: up one dir, main page]

Skip to content

Commit 48d6fda

Browse files
committed
Simplify parameter handling in FloatingAxesBase.
- `grid_helper` can just become a standard kwonly arg. - `GridHelperCurveLinear` is the only class that defines `get_boundary`, so in practice the hasattr check is the same as an isinstance check. (It is technically possible that someone wrote their own GridHelperCurveLinear-like subclass with the same API, but let's not overly worry about that... and they can always still completely inherit GridHelperCurveLinear and full override everything if really needed.)
1 parent de2ea8b commit 48d6fda

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

lib/mpl_toolkits/axisartist/floating_axes.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99

1010
import numpy as np
1111

12+
from matplotlib import _api
13+
import matplotlib.axes as maxes
1214
import matplotlib.patches as mpatches
1315
from matplotlib.path import Path
14-
import matplotlib.axes as maxes
1516

1617
from mpl_toolkits.axes_grid1.parasite_axes import host_axes_class_factory
1718

@@ -312,13 +313,9 @@ def get_boundary(self):
312313

313314
class FloatingAxesBase:
314315

315-
def __init__(self, *args, **kwargs):
316-
grid_helper = kwargs.get("grid_helper", None)
317-
if grid_helper is None:
318-
raise ValueError("FloatingAxes requires grid_helper argument")
319-
if not hasattr(grid_helper, "get_boundary"):
320-
raise ValueError("grid_helper must implement get_boundary method")
321-
super().__init__(*args, **kwargs)
316+
def __init__(self, *args, grid_helper, **kwargs):
317+
_api.check_isinstance(GridHelperCurveLinear, grid_helper=grid_helper)
318+
super().__init__(*args, grid_helper=grid_helper, **kwargs)
322319
self.set_aspect(1.)
323320
self.adjust_axes_lim()
324321

0 commit comments

Comments
 (0)
0