@@ -268,8 +268,10 @@ def rename_parameter(since, old, new, func=None):
268
268
def func(good_name): ...
269
269
"""
270
270
271
+ decorator = functools .partial (rename_parameter , since , old , new )
272
+
271
273
if func is None :
272
- return functools . partial ( rename_parameter , since , old , new )
274
+ return decorator
273
275
274
276
signature = inspect .signature (func )
275
277
assert old not in signature .parameters , (
@@ -294,6 +296,7 @@ def wrapper(*args, **kwargs):
294
296
# would both show up in the pyplot function for an Axes method as well and
295
297
# pyplot would explicitly pass both arguments to the Axes method.
296
298
299
+ wrapper ._mpl_decorator = decorator # cf _copy_docstring_and_deprecators.
297
300
return wrapper
298
301
299
302
@@ -330,8 +333,10 @@ def delete_parameter(since, name, func=None, **kwargs):
330
333
def func(used_arg, other_arg, unused, more_args): ...
331
334
"""
332
335
336
+ decorator = functools .partial (delete_parameter , since , name , ** kwargs )
337
+
333
338
if func is None :
334
- return functools . partial ( delete_parameter , since , name , ** kwargs )
339
+ return decorator
335
340
336
341
signature = inspect .signature (func )
337
342
# Name of `**kwargs` parameter of the decorated function, typically
@@ -399,17 +404,24 @@ def wrapper(*inner_args, **inner_kwargs):
399
404
** kwargs )
400
405
return func (* inner_args , ** inner_kwargs )
401
406
407
+ wrapper ._mpl_decorator = decorator # cf _copy_docstring_and_deprecators.
402
408
return wrapper
403
409
404
410
405
411
def make_keyword_only (since , name , func = None ):
406
412
"""
407
413
Decorator indicating that passing parameter *name* (or any of the following
408
414
ones) positionally to *func* is being deprecated.
415
+
416
+ When used on a method that has a pyplot wrapper, this should be the
417
+ outermost decorator, so that :file:`boilerplate.py` can access the original
418
+ signature.
409
419
"""
410
420
421
+ decorator = functools .partial (make_keyword_only , since , name )
422
+
411
423
if func is None :
412
- return functools . partial ( make_keyword_only , since , name )
424
+ return decorator
413
425
414
426
signature = inspect .signature (func )
415
427
POK = inspect .Parameter .POSITIONAL_OR_KEYWORD
@@ -421,16 +433,13 @@ def make_keyword_only(since, name, func=None):
421
433
names = [* signature .parameters ]
422
434
kwonly = [name for name in names [names .index (name ):]
423
435
if signature .parameters [name ].kind == POK ]
424
- func .__signature__ = signature .replace (parameters = [
425
- param .replace (kind = KWO ) if param .name in kwonly else param
426
- for param in signature .parameters .values ()])
427
436
428
437
@functools .wraps (func )
429
438
def wrapper (* args , ** kwargs ):
430
439
# Don't use signature.bind here, as it would fail when stacked with
431
440
# rename_parameter and an "old" argument name is passed in
432
441
# (signature.bind would fail, but the actual call would succeed).
433
- idx = [ * func . __signature__ . parameters ] .index (name )
442
+ idx = names .index (name )
434
443
if len (args ) > idx :
435
444
warn_deprecated (
436
445
since , message = "Passing the %(name)s %(obj_type)s "
@@ -439,6 +448,11 @@ def wrapper(*args, **kwargs):
439
448
name = name , obj_type = f"parameter of { func .__name__ } ()" )
440
449
return func (* args , ** kwargs )
441
450
451
+ # Don't modify *func*'s signature, as boilerplate.py needs it.
452
+ wrapper .__signature__ = signature .replace (parameters = [
453
+ param .replace (kind = KWO ) if param .name in kwonly else param
454
+ for param in signature .parameters .values ()])
455
+ wrapper ._mpl_decorator = decorator # cf _copy_docstring_and_deprecators.
442
456
return wrapper
443
457
444
458
0 commit comments