@@ -107,37 +107,37 @@ def limit_range_for_scale(self, vmin, vmax, minpos):
107
107
108
108
def handle_axis_parameter (init_func ):
109
109
"""
110
- Allow scale classes to work with or without the ` axis` parameter .
110
+ Decorator to support scale constructors that optionally accept an axis.
111
111
112
- This decorator enables scale constructors to maintain backward
113
- compatibility with older code that passes `axis`, while allowing
114
- future implementations to omit it entirely.
115
-
116
- If the wrapped constructor defines `axis` as its first argument,
117
- the parameter is
8000
preserved. Otherwise, it is safely removed from
118
- positional or keyword arguments.
112
+ This decorator provides backward compatibility for scale classes that
113
+ used to require an *axis* parameter. It allows scale constructors to
114
+ function whether or not the *axis* argument is provided.
119
115
120
116
Parameters
121
117
----------
122
118
init_func : callable
123
- The original __init__ method of a scale class.
119
+ The original `` __init__`` method of a scale class.
124
120
125
121
Returns
126
122
-------
127
123
callable
128
- A wrapped version of `init_func` that handles the optional `axis`.
124
+ A wrapped version of ``init_func`` that supports the optional *axis*
125
+ parameter.
126
+
127
+ Notes
128
+ -----
129
+ If the constructor defines *axis* explicitly as its first parameter, the
130
+ argument is preserved. Otherwise, it is removed from positional and keyword
131
+ arguments before calling the constructor.
132
+
133
+ Examples
134
+ --------
135
+ >>> from matplotlib.scale import ScaleBase
136
+ >>> class CustomScale(ScaleBase):
137
+ ... @handle_axis_parameter
138
+ ... def __init__(self, axis=None, custom_param=1):
139
+ ... self.custom_param = custom_param
129
140
"""
130
- @wraps (init_func )
131
- def wrapper (self , * args , ** kwargs ):
132
- sig = inspect .signature (init_func )
133
- params = list (sig .parameters .values ())
134
- if params and params [1 ].name == "axis" :
135
- return init_func (self , * args , ** kwargs )
136
- if args :
137
- args = args [1 :]
138
- kwargs .pop ("axis" , None )
139
- return init_func (self , * args , ** kwargs )
140
- return wrapper
141
141
142
142
143
143
class LinearScale (ScaleBase ):
0 commit comments