-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add a select_overload helper for signature-overloaded functions. #20420
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
lib/matplotlib/_api/__init__.py
Outdated
def select_overload(funcs, *args, **kwargs): | ||
""" | ||
Select the function signature that accepts ``*args, **kwargs``, and return | ||
a mapping of bound arguments. | ||
|
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.
The name is still pretty mysterious. Maybe:
def select_overload(funcs, *args, **kwargs): | |
""" | |
Select the function signature that accepts ``*args, **kwargs``, and return | |
a mapping of bound arguments. | |
def select_function_sigature(funcs, *args, **kwargs): | |
""" | |
Match a user-supplied set of arguments to a method (as defined in ``*args, **kwargs``) with two or | |
more signatures, and return a mapping of bound arguments to the chosen signature. Useful when | |
changing the signature of a method but keeping back compatibility; usually the back-compatible | |
signature will still be passed, but with a deprecation warning. |
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.
Overloading is pretty standard terminology (https://en.wikipedia.org/wiki/Function_overloading).
The use case is explained quite in length in the Notes.
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.
If you are going to insist on jargon, we should at least need to make it google-able, so maybe select_function_overload
? "function overload" at least gets me to the right place, "overload" is too general. No doubt I am more ignorant than most of our contributors, but having select_overload
show up in the middle of the code does not tell me what I am looking at, whereas select_function_signature
does.
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.
Fair enough re: googlability.
What about select_matching_signature
?
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.
That would be great for me...
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.
select_matching_signature it is, then.
5805e07
to
e666939
Compare
I slightly changed the implementation (and API), to get back to the performance of the hand-written lambdas (Signature.bind is slow, it is better to let Python's normal call machinery do the binding). |
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 think this is very helpful if we are going to do this kind of deprecation often. The name is helpful, and the description on the function has the necessary details.
PR Summary
This was suggested by @jklymak in #20354 (comment). That PR is not merged yet, so right now the only use site is the QuadMesh constructor.
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).