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

Skip to content

Commit 61c99b6

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

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
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):

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ def set_zscale(self, value, **kwargs):
829829
get_zticklabels = _axis_method_wrapper("zaxis", "get_ticklabels")
830830
set_zticklabels = _axis_method_wrapper(
831831
"zaxis", "_set_ticklabels",
832-
doc_sub={"Axis.set_ticks": "Axes.set_zticks"})
832+
doc_sub={"Axis.set_ticks": "Axes3D.set_zticks"})
833833

834834
zaxis_date = _axis_method_wrapper("zaxis", "axis_date")
835835
if zaxis_date.__doc__:

0 commit comments

Comments
 (0)