Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit de876cc

Browse files
committed
Use __set_name__ for better wrapping.
1 parent 73e44cc commit de876cc

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from collections import OrderedDict
22
from contextlib import ExitStack
3-
import functools
43
import inspect
54
import itertools
65
import logging
@@ -49,14 +48,17 @@ def _axis_method_wrapper(attr_name, method_name, *, doc_sub=None):
4948
dedented to simplify further manipulations.
5049
"""
5150

52-
method = getattr(maxis.Axis, method_name)
5351
get_method = attrgetter(f"{attr_name}.{method_name}")
5452

55-
@functools.wraps(method)
5653
def wrapper(self, *args, **kwargs):
5754
return get_method(self)(*args, **kwargs)
5855

59-
doc = wrapper.__doc__
56+
# Manually copy the signature instead of using functools.wraps because
57+
# displaying the Axis method source when asking for the Axes method source
58+
# would be confusing.
59+
wrapped_method = getattr(maxis.Axis, method_name)
60+
wrapper.__signature__ = inspect.signature(wrapped_method)
61+
doc = wrapped_method.__doc__
6062
if doc:
6163
doc_sub = {"this Axis": f"the {attr_name}", **(doc_sub or {})}
6264
for k, v in doc_sub.items():
@@ -66,7 +68,14 @@ def wrapper(self, *args, **kwargs):
6668
doc = doc.replace(k, v)
6769
wrapper.__doc__ = inspect.cleandoc(doc)
6870

69-
return wrapper
71+
class Placeholder:
72+
def __set_name__(self, owner, name):
73+
wrapper.__module__ = owner.__module__
74+
wrapper.__name__ = name
75+
wrapper.__qualname__ = f"{owner.__qualname__}.{name}"
76+
setattr(owner, name, wrapper)
77+
78+
return Placeholder()
7079

7180

7281
def _process_plot_format(fmt):

0 commit comments

Comments
 (0)