Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit61c99b6

Browse files
committed
Use __set_name__ for better wrapping.
1 parent73e44cc commit61c99b6

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
fromcollectionsimportOrderedDict
22
fromcontextlibimportExitStack
3-
importfunctools
43
importinspect
54
importitertools
65
importlogging
@@ -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
defwrapper(self,*args,**kwargs):
5754
returnget_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
ifdoc:
6163
doc_sub= {"this Axis":f"the{attr_name}",**(doc_subor {})}
6264
fork,vindoc_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-
returnwrapper
71+
classPlaceholder:
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+
returnPlaceholder()
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
ifzaxis_date.__doc__:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp