Skip to content

making onselect a keyword argument on selectors#26000

Merged
timhoffm merged 1 commit into
matplotlib:mainfrom
thiagoluisbecker:onselect_noop
Sep 20, 2024
Merged

making onselect a keyword argument on selectors#26000
timhoffm merged 1 commit into
matplotlib:mainfrom
thiagoluisbecker:onselect_noop

Conversation

@thiagoluisbecker

Copy link
Copy Markdown
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
Comment thread lib/matplotlib/widgets.py Outdated
Comment thread lib/matplotlib/widgets.py Outdated
"""

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

Copy link
Copy Markdown
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

oscargus commented Jun 1, 2023

Copy link
Copy Markdown
Member

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

oscargus commented Jun 1, 2023

Copy link
Copy Markdown
Member

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

@tacaswell tacaswell left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
Contributor Author

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

@timhoffm

timhoffm commented Aug 4, 2023

Copy link
Copy Markdown
Member

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

@thiagoluisbecker

Copy link
Copy Markdown
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

QuLogic commented Sep 20, 2024

Copy link
Copy Markdown
Member

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

@oscargus oscargus left a comment

Copy link
Copy Markdown
Member

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.

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
@melissawm melissawm moved this from Waiting for author to Merged in First Time Contributors Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

[MNT]: Deprecate onselect/onmove_callback of selectors

8 participants