-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add explicit signatures for pyplot.{polar,savefig,set_loglevel} #30200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor suggestions, but I'm fine either way.
…pyplot-signatures
You are right, however, changing the signature would break the added test that was created (because it's tied to the |
Looking at the polar code agian, we should rather modify the signature to become This will be for a separate PR, so please revert the polar change here. Technically, we first need to deprecate other signatures by checking that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert the polar part as discussed above.
Reverted as requested 👍 |
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
lib/matplotlib/tests/test_pyplot.py
Outdated
@@ -484,3 +486,71 @@ def test_matshow(): | |||
|
|||
# Smoke test that matshow does not ask for a new figsize on the existing figure | |||
plt.matshow(arr, fignum=fig.number) | |||
|
|||
|
|||
def assert_signatures_identical(plt_meth, original_meth, remove_self_param=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t have time to check the details, but this functions seems quite heavy-weight now that we only check the really simple function set_loglevel. Do we really bread/want that complexity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a bit complex; we could extend the test to cover additional things in a later PR like plt.rc
, plt.getp
, plt.figlegend
, plt.imread
, plt.imsave
, and maybe some others, but that does hit some limitations; I think the test as written doesn't handle overloads, and making it do that also might be more trouble than it's worth.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. The complexity arises from ensuring identical typing.
As long as it's only about set_loglevel()
, it would be sufficient for me to check identical names and numbers of arguments. That ensures identical runtime behavior. At the same time, this is probably the biggest risk: We modify the signature (renaming, adding arguments) and don't sync that. It's rather unlikely that we change the declared types - and even if that'd happen it's only a type-checking issue not a runtime issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have replaced with a low cost check. In addition to the names and numbers, I also check the kinds.
… parameters) with assert_same_signature (only check len(parameters), names and kinds)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks much better in terms of matching simplicity with the test goals. Only a minor naming suggestion remains.
PR summary
This PR update
lib/matplotlib/pyplot.py
to replace*args, **kwargs
with the real signature for the following methods:savefig
set_loglevel
polar
PR checklist