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

Skip to content

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

Merged
merged 1 commit into from
Jun 18, 2021

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jun 12, 2021

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

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@anntzer anntzer mentioned this pull request Jun 12, 2021
7 tasks
Comment on lines 193 to 195
def select_overload(funcs, *args, **kwargs):
"""
Select the function signature that accepts ``*args, **kwargs``, and return
a mapping of bound arguments.

Copy link
Member

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:

Suggested change
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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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...

Copy link
Contributor Author

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.

@anntzer anntzer force-pushed the select_overload branch 2 times, most recently from 5805e07 to e666939 Compare June 13, 2021 09:24
@anntzer
Copy link
Contributor Author

anntzer commented Jun 13, 2021

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).

Copy link
Member

@jklymak jklymak left a 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.

@QuLogic QuLogic merged commit f008953 into matplotlib:master Jun 18, 2021
@QuLogic QuLogic added this to the v3.5.0 milestone Jun 18, 2021
@anntzer anntzer deleted the select_overload branch June 18, 2021 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants