Skip to content

making onselect a keyword argument on selectors #26000

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
Sep 20, 2024

Conversation

thiagoluisbecker
Copy link
Contributor

PR summary

closes #21929
Making onselect a keyword argument on Selectors(widgets.py) with no-op functions following the suggestion made in this issue comment: #21929 (comment).

PR checklist

@thiagoluisbecker thiagoluisbecker marked this pull request as draft May 29, 2023 19:38
@thiagoluisbecker thiagoluisbecker marked this pull request as ready for review May 29, 2023 23:39
@@ -3245,7 +3249,8 @@ class RectangleSelector(_SelectorWidget):
See also: :doc:`/gallery/widgets/rectangle_selector`
"""

def __init__(self, ax, onselect, *, minspanx=0, minspany=0, useblit=False,
def __init__(self, ax, *, onselect=None, minspanx=0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __init__(self, ax, *, onselect=None, minspanx=0,
def __init__(self, ax, onselect=None, *, minspanx=0,

The * makes it keyword only which would require deprecation etc. I think it make sense to provide a default value, but not require old code to pass onselect with a keyword. (I guess you just forgot about this line.)

@oscargus
Copy link
Member

oscargus commented Jun 1, 2023

Not really sure about the mypy tests. I think you need to update the widget.pyi-file, probably with the default values so that the signatures match.

Also, I think it would be good to add a "smoke test" for this. That is, call one of the selectors without an onselect callback. I'd create a new test that doesn't have an argument for onselect and then add a comment like:

# Smoke test for creating selector without callback

before that call.

@oscargus
Copy link
Member

oscargus commented Jun 1, 2023

Oh, and reading #21929 I am not sure that this closes the issue. It is clearly a good contribution taking care of parts of it though.

@tacaswell tacaswell added this to the v3.8.0 milestone Jun 1, 2023
Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with Oscar, changing to keyword only is a breaking change.

We should either go with just giving it a default value to make it optional (my preference) or actually do the derprecation (see the _api.make_keyword_only decorator that already exists in this file).

One way or the other we need a whats new and/or API change note.

Anyone can dismiss this review.

@tacaswell
Copy link
Member

Thank you for your work on this @thiagoluisbecker .

Could you also add a test of creating Selector object without passing the onselect (to actually exercise the default path!).

@thiagoluisbecker
Copy link
Contributor Author

Hi! Apologies for the delay. I understand the suggestions and I will implement them. Thanks for the answers.

@timhoffm
Copy link
Member

timhoffm commented Aug 4, 2023

ping @thiagoluisbecker. Are you still planning to work on this?

@thiagoluisbecker
Copy link
Contributor Author

Hi! No.

@rcomer rcomer marked this pull request as draft August 4, 2023 16:38
@ksunden ksunden modified the milestones: v3.8.0, v3.9.0 Aug 8, 2023
@QuLogic QuLogic modified the milestones: v3.9.0, v3.10.0 Mar 13, 2024
@QuLogic
Copy link
Member

QuLogic commented Sep 20, 2024

This seems straightforward, so I've rebased, fixed the comments, added a what's new note, and modified tests to drop the onselect argument everywhere it used noop (but not where it used Mock with noop).

Also note that there's also SpanSelector that has an onselect parameter, but it can't be made optional because the direction parameter comes after it.

@QuLogic QuLogic marked this pull request as ready for review September 20, 2024 07:01
Copy link
Member

@oscargus oscargus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subject to deciding if it #21929 should be closed or not.

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good step forward and does not bar later removal. In fact, it makes it slightly simpler since people can from now on leave out onselect if they don't need it, which will make their code forward-compatible with a possible future removal.

@timhoffm
Copy link
Member

Optional: We could deprecate for kw-only use for onselect and following arguments, which would make potential later removal simpler. But that can also be done in a follow-up.

@timhoffm timhoffm merged commit fe6389f into matplotlib:main Sep 20, 2024
41 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for author
Development

Successfully merging this pull request may close these issues.

[MNT]: Deprecate onselect/onmove_callback of selectors
7 participants