Skip to content
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

bpo-31485: Fix Misc.unbind behaviour when funcid is given #17954

Open
wants to merge 5 commits into
base: master
from

Conversation

@GiovaLomba
Copy link

GiovaLomba commented Jan 11, 2020

GiovaLomba added 2 commits Jan 6, 2020
Allows Misc.unbind to delete only the bound callback
having the given funcid. See the issue above for more.
bpo-31485: Fix Misc.unbind behaviour when funcid is given
@the-knights-who-say-ni

This comment has been minimized.

Copy link

the-knights-who-say-ni commented Jan 11, 2020

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@GiovaLomba

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@vstinner

This comment has been minimized.

Copy link
Member

vstinner commented Jan 14, 2020

@GiovaLomba

This comment has been minimized.

Copy link
Author

GiovaLomba commented Jan 14, 2020

About the ubuntu test failure: it happens at cpython/Lib/idlelib/multicall.py, line 241 in __del__. Having a look at the code it appears that, for reasons unknown to me, on Ubuntu when the destructor is called functions in tk have already been gone and hence the deletecommand(funcid) raises Can't delete Tcl command. As a workaround to Ubuntu specific behaviour, and maybe future changes in the tk library itself, exception handling could be added around the deletecommand(funcid) call, avoiding exception being raised when funcid does not exists anymore. What's your opinion?

Copy link
Member

terryjreedy left a comment

I think a new test is needed to verify that the revision does what we want and expect it to.

self.tk.call('bind', self._w, sequence, '')
"""Unbind for this widget the event SEQUENCE. if
FUNCID is given, delete the command also."""
bound = ''
if funcid:
self.deletecommand(funcid)

This comment has been minimized.

Copy link
@terryjreedy

terryjreedy Jan 14, 2020

Member

The test failure is here, _tkinter.TclError: can't delete Tcl command. In the absence of more specific information, I interpret this as tk, on Linux, refusing to delete a command that is in use. Try moving the deletion back to after the rebinding, as it originally was. It is OK to have two if funcid clauses.

This comment has been minimized.

Copy link
@GiovaLomba

GiovaLomba Jan 14, 2020

Author

Should this work? I've just given it a try on Ubuntu and tests worked.

    def unbind(self, sequence, funcid=None):
        """Unbind for this widget the event SEQUENCE. if
        FUNCID is given, delete the command also."""
        funcs = self.tk.call('bind', self._w, sequence, None)
        self.tk.call('bind', self._w, sequence, '')
        if funcid:
            self.deletecommand(funcid)
            keep = '\n'.join(f for f in funcs.split('\n') if not f.startswith(f'if {{"[{funcid}'))
            self.tk.call('bind', self._w, sequence, keep)

Where should the test be written? Would the test just check that after unbind with given funcid, other bound function are there and the given one is gone?

Lib/tkinter/__init__.py Outdated Show resolved Hide resolved
Lib/tkinter/__init__.py Outdated Show resolved Hide resolved
@bedevere-bot

This comment has been minimized.

Copy link

bedevere-bot commented Jan 14, 2020

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

GiovaLomba added 2 commits Jan 15, 2020
Fix `_tkinter.TclError: can't delete Tcl command` on Ubuntu bionic.
Change `bound` to `keep` as suggested.
@GiovaLomba GiovaLomba requested a review from terryjreedy Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.