classification
Title: tkinter after_cancel does not behave correctly when called with id=None
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.8, Python 3.7, Python 3.6, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: cheryl.sabella, miss-islington, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2018-02-16 13:20 by cheryl.sabella, last changed 2018-05-05 13:20 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 5701 merged cheryl.sabella, 2018-02-16 19:41
PR 5972 merged miss-islington, 2018-03-04 10:42
PR 5973 merged miss-islington, 2018-03-04 10:44
PR 6620 merged cheryl.sabella, 2018-04-27 19:42
Messages (11)
msg312231 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-02-16 13:20
This was discovered while working on issue32839.  An old comment added for issue763637 resulted in further research and it was determined that the comment:

!             data = self.tk.call('after', 'info', id)
!             # In Tk 8.3, splitlist returns: (script, type)
!             # In Tk 8.4, splitlist returns: (script,)

wasn't correct.  The underlying difference is that the call to 'after info' returns different results depending on the way it's called.  If it's called with an 'id', it will return a tuple of (script, type) if the id is valid or a TclError if the id isn't valid.  However, if id is None, then 'after info' returns a tuple of all the event ids for the widget.  In the case of the original bug in issue763637, the reported message shows the return value of `('after#53',)`, which is definitely an after event id and not a (script,) tuple.

Serhiy mentions on issue32839 that the current code also deletes the script for the first event if after_cancel is called with None.
https://bugs.python.org/issue32839#msg312199
msg312233 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-02-16 13:45
I can open a PR for this, but thought it might be best to discuss it first as far as what should happen with None.

1. Raise an error that it's an incorrect call.
2. Ignore it and just return.
3. Loop through all the events and after_cancel each one. 

Tcl allows the after_cancel call to be an id or script(s), but they don't have functionality that would cancel everything (unless all the `script` values were sent).

FWIW, if no parameters are sent, this is the Tcl code:
	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "id|command");
	    return TCL_ERROR;
	}
msg312234 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-02-16 14:39
I prefer the option 1. Even if calling after_cancel(None) would make sense, currently it silently does wrong things, and it is more errorproof to make it raising an exception.
msg312349 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-02-19 12:46
I have noticed that there are no tests for after() and after_cancel(). Maybe first write tests for them and later add a test for this specific issue to them?
msg312384 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-02-19 23:50
I had also noticed that the `after` commands didn't have tests.  Did you want me to add tests in a separate issue before this one is merged or did you want me to add tests under this PR?

Thanks!
msg312404 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-02-20 08:57
It's up to you.
msg312566 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-02-22 14:13
I've added the tests for `after` and `after_idle`.  I used `update` and `update_idletasks` to make sure they processed.  Even scheduling an after event for 0 ms didn't guarantee it would process, but I wasn't sure if there was a better way besides `update` to get it to process?
msg313207 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-03-04 10:41
New changeset 74382a3f175ac285cc924a73fd758e8dc3cc41bb by Serhiy Storchaka (Cheryl Sabella) in branch 'master':
bpo-32857: Raise error when tkinter after_cancel() is called with None. (GH-5701)
https://github.com/python/cpython/commit/74382a3f175ac285cc924a73fd758e8dc3cc41bb
msg313209 - (view) Author: miss-islington (miss-islington) Date: 2018-03-04 11:42
New changeset 73a43960c7be50e136c5482404980175cb99f611 by Miss Islington (bot) in branch '3.6':
bpo-32857: Raise error when tkinter after_cancel() is called with None. (GH-5701)
https://github.com/python/cpython/commit/73a43960c7be50e136c5482404980175cb99f611
msg313210 - (view) Author: miss-islington (miss-islington) Date: 2018-03-04 12:00
New changeset a5303dd9c263b337f02dda0038f2f5a10208140c by Miss Islington (bot) in branch '3.7':
bpo-32857: Raise error when tkinter after_cancel() is called with None. (GH-5701)
https://github.com/python/cpython/commit/a5303dd9c263b337f02dda0038f2f5a10208140c
msg316208 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-05-05 13:10
New changeset 3a04598f63960e72025a91c682aec51b6b460413 by Serhiy Storchaka (Cheryl Sabella) in branch '2.7':
bpo-32857: Raise error when tkinter after_cancel() is called with None. (GH-5701) (GH-6620)
https://github.com/python/cpython/commit/3a04598f63960e72025a91c682aec51b6b460413
History
Date User Action Args
2018-05-05 13:20:35serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-05-05 13:10:50serhiy.storchakasetmessages: + msg316208
2018-04-27 19:42:06cheryl.sabellasetpull_requests: + pull_request6316
2018-03-04 13:45:03cheryl.sabellalinkissue32839 dependencies
2018-03-04 12:00:35miss-islingtonsetmessages: + msg313210
2018-03-04 11:42:47miss-islingtonsetnosy: + miss-islington
messages: + msg313209
2018-03-04 10:44:56miss-islingtonsetpull_requests: + pull_request5739
2018-03-04 10:42:56miss-islingtonsetpull_requests: + pull_request5738
2018-03-04 10:41:51serhiy.storchakasetmessages: + msg313207
2018-02-22 14:13:54cheryl.sabellasetmessages: + msg312566
2018-02-20 08:57:18serhiy.storchakasetmessages: + msg312404
2018-02-19 23:50:35cheryl.sabellasetmessages: + msg312384
2018-02-19 12:46:16serhiy.storchakasetmessages: + msg312349
2018-02-16 19:41:50cheryl.sabellasetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request5490
2018-02-16 14:47:43serhiy.storchakasetstage: needs patch
versions: + Python 2.7, Python 3.6, Python 3.7
2018-02-16 14:39:23serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg312234
2018-02-16 13:45:27cheryl.sabellasetmessages: + msg312233
2018-02-16 13:20:14cheryl.sabellacreate