@@ -1262,29 +1262,40 @@ def _make_norm_from_scale(scale_cls, base_norm_cls=None, *, init=None):
1262
1262
After ::
1263
1263
1264
1264
@_make_norm_from_scale(scale_cls)
1265
- class base_norm_cls (Normalize):
1265
+ class norm_cls (Normalize):
1266
1266
...
1267
1267
1268
- *base_norm_cls* is filled with methods so that normalization computations
1269
- are forwarded to *scale_cls* (i.e., *scale_cls* is the scale that would be
1270
- used for the colorbar of a mappable normalized with *base_norm_cls*).
1271
-
1272
- The constructor signature of *base_norm_cls* is derived from the
1273
- constructor signature of *scale_cls*, but can be overridden using *init*
1274
- (a callable which is *only* used for its signature).
1268
+ *norm_cls* is filled with methods so that normalization computations are
1269
+ forwarded to *scale_cls* (i.e., *scale_cls* is the scale that would be used
1270
+ for the colorbar of a mappable normalized with *norm_cls*).
1271
+
1272
+ If *init* is not passed, then the constructor signature of *norm_cls*
1273
+ will be ``norm_cls(vmin=None, vmax=None, clip=False)``; these three
1274
+ parameters will be forwarded to the base class (``Normalize.__init__``),
1275
+ and a *scale_cls* object will be initialized with no arguments (other than
1276
+ a dummy axis).
1277
+
1278
+ If the *scale_cls* constructor takes additional parameters, then *init*
1279
+ should be passed to `_make_norm_from_scale`. It is a callable which is
1280
+ *only* used for its signature. First, this signature will become the
1281
+ signature of *norm_cls*. Second, the *norm_cls* constructor will bind the
1282
+ parameters passed to it using this signature, extract the bound *vmin*,
1283
+ *vmax*, and *clip* values, pass those to ``Normalize.__init__``, and
1284
+ forward the remaining bound values (including any defaults defined by the
1285
+ signature) to the *scale_cls* constructor.
1275
1286
"""
1276
1287
1277
1288
if base_norm_cls is None :
1278
1289
return functools .partial (_make_norm_from_scale , scale_cls , init = init )
1279
1290
1280
1291
if init is None :
1281
1292
def init (vmin = None , vmax = None , clip = False ): pass
1282
- init_signature = inspect .signature (init )
1293
+ bound_init_signature = inspect .signature (init )
1283
1294
1284
1295
class Norm (base_norm_cls ):
1285
1296
1286
1297
def __init__ (self , * args , ** kwargs ):
1287
- ba = init_signature .bind (* args , ** kwargs )
1298
+ ba = bound_init_signature .bind (* args , ** kwargs )
1288
1299
ba .apply_defaults ()
1289
1300
super ().__init__ (
1290
1301
** {k : ba .arguments .pop (k ) for k in ["vmin" , "vmax" , "clip" ]})
@@ -1329,6 +1340,9 @@ def inverse(self, value):
1329
1340
Norm .__name__ = base_norm_cls .__name__
1330
1341
Norm .__qualname__ = base_norm_cls .__qualname__
1331
1342
Norm .__module__ = base_norm_cls .__module__
1343
+ Norm .__init__ .__signature__ = bound_init_signature .replace (parameters = [
1344
+ inspect .Parameter ("self" , inspect .Parameter .POSITIONAL_OR_KEYWORD ),
1345
+ * bound_init_signature .parameters .values ()])
1332
1346
return Norm
4135
1333
1347
1334
1348
0 commit comments