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

Commit0e430b9

Browse files
ZPyrolinkCorenthinZQuLogic
authored
Add explicit signatures for pyplot.{polar,savefig,set_loglevel} (#30200)
* Create tests(cherry picked from commit608b51f)* Update test_pyplot.py to include type on signature(cherry picked from commit4ea0ff8)* Update polar and set_loglevel signature on pyplot.py(cherry picked from commit41b701b)* Update savefig signature on pyplot.py(cherry picked from commitb863ba2)* Add type hint on polar and set_loglevel on pyplot.py. Correct polar content(cherry picked from commit92dc045)* Format with ruff(cherry picked from commit64e7921)* Revert polar on pyplot.py and remove corresponding test* Remove extra work when stub file doesn't existsCo-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>* Replace assert_signatures_identical (check return_annotation and full parameters) with assert_same_signature (only check len(parameters), names and kinds)* Remove unused import* Renaming assert_signature arguments* Correct typo and ruff error---------Co-authored-by: Corenthin ZOZOR <corenthin.zozor@gmail.com>Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
1 parent9c184c1 commit0e430b9

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

‎lib/matplotlib/pyplot.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
importsys
5151
importthreading
5252
importtime
53-
fromtypingimportTYPE_CHECKING,cast,overload
53+
fromtypingimportIO,TYPE_CHECKING,cast,overload
5454

5555
fromcyclerimportcycler# noqa: F401
5656
importmatplotlib
@@ -338,8 +338,8 @@ def uninstall_repl_displayhook() -> None:
338338

339339
# Ensure this appears in the pyplot docs.
340340
@_copy_docstring_and_deprecators(matplotlib.set_loglevel)
341-
defset_loglevel(*args,**kwargs)->None:
342-
returnmatplotlib.set_loglevel(*args,**kwargs)
341+
defset_loglevel(level:str)->None:
342+
returnmatplotlib.set_loglevel(level)
343343

344344

345345
@_copy_docstring_and_deprecators(Artist.findobj)
@@ -1259,11 +1259,11 @@ def draw() -> None:
12591259

12601260

12611261
@_copy_docstring_and_deprecators(Figure.savefig)
1262-
defsavefig(*args,**kwargs)->None:
1262+
defsavefig(fname:str|os.PathLike|IO,**kwargs)->None:
12631263
fig=gcf()
12641264
# savefig default implementation has no return, so mypy is unhappy
12651265
# presumably this is here because subclasses can return?
1266-
res=fig.savefig(*args,**kwargs)# type: ignore[func-returns-value]
1266+
res=fig.savefig(fname,**kwargs)# type: ignore[func-returns-value]
12671267
fig.canvas.draw_idle()# Need this if 'transparent=True', to reset colors.
12681268
returnres
12691269

‎lib/matplotlib/tests/test_pyplot.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
importdifflib
2+
importinspect
23

34
importnumpyasnp
45
importsys
@@ -484,3 +485,26 @@ def test_matshow():
484485

485486
# Smoke test that matshow does not ask for a new figsize on the existing figure
486487
plt.matshow(arr,fignum=fig.number)
488+
489+
490+
defassert_same_signature(func1,func2):
491+
"""
492+
Assert that `func1` and `func2` have the same arguments,
493+
i.e. same parameter count, names and kinds.
494+
495+
:param func1: First function to check
496+
:param func2: Second function to check
497+
"""
498+
params1=inspect.signature(func1).parameters
499+
params2=inspect.signature(func2).parameters
500+
501+
assertlen(params1)==len(params2)
502+
assertall([
503+
params1[p].name==params2[p].nameand
504+
params1[p].kind==params2[p].kind
505+
forpinparams1
506+
])
507+
508+
509+
deftest_setloglevel_signature():
510+
assert_same_signature(plt.set_loglevel,mpl.set_loglevel)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp