@@ -107,28 +107,27 @@ def limit_range_for_scale(self, vmin, vmax, minpos):
107
107
108
108
def handle_axis_parameter (init_func ):
109
109
"""
110
- Decorator to support scale constructors that optionally accept an axis .
110
+ Decorator to handle the optional *axis* parameter in scale constructors .
111
111
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 .
112
+ This decorator ensures backward compatibility for scale classes that
113
+ previously required an *axis* parameter. It allows constructors to work
114
+ seamlessly with or without the *axis* parameter .
115
115
116
116
Parameters
117
117
----------
118
118
init_func : callable
119
- The original `` __init__`` method of a scale class.
119
+ The original __init__ method of a scale class.
120
120
121
121
Returns
122
122
-------
123
123
callable
124
- A wrapped version of ``init_func`` that supports the optional *axis*
125
- parameter.
124
+ A wrapped version of *init_func* that handles the optional *axis*.
126
125
127
126
Notes
128
127
-----
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 .
128
+ If the wrapped constructor defines *axis* as its first argument , the
129
+ parameter is preserved. Otherwise, it is safely removed from positional
130
+ or keyword arguments .
132
131
133
132
Examples
134
133
--------
@@ -138,6 +137,17 @@ def handle_axis_parameter(init_func):
138
137
... def __init__(self, axis=None, custom_param=1):
139
138
... self.custom_param = custom_param
140
139
"""
140
+ @wraps (init_func )
141
+ def wrapper (self , * args , ** kwargs ):
142
+ sig = inspect .signature (init_func )
143
+ params = list (sig .parameters .values ())
144
+ if params and params [1 ].name == "axis" :
145
+ return init_func (self , * args , ** kwargs )
146
+ if args :
147
+ args = args [1 :]
148
+ kwargs .pop ("axis" , None )
149
+ return init_func (self , * args , ** kwargs )
150
+ return wrapper
141
151
142
152
143
153
class LinearScale (ScaleBase ):
0 commit comments