bpo-32857: tkinter after_cancel to raise error if called with None#5701
bpo-32857: tkinter after_cancel to raise error if called with None#5701serhiy-storchaka merged 4 commits intopython:masterfrom
Conversation
|
|
||
| # Cancel timer event. | ||
| (script, _) = root.tk.splitlist(root.tk.call('after', 'info', timer1)) | ||
| self.assertIn(script, root._tclCommands) |
There was a problem hiding this comment.
_tclCommands is an implementation detail. It would be better to not use it in tests. Otherwise changing the implementation (it already was changed in the past) will break tests.
But you can test a side effect of the script by calling root.tk.call(script).
There was a problem hiding this comment.
Thank you for this suggestion. I wasn't quite sure how to test that the script still existed after the cancel.
| with self.assertRaises(ValueError): | ||
| root.after_cancel(None) | ||
|
|
||
| # A non-existent id raises a TclError, which is caught in after_cancel. |
There was a problem hiding this comment.
The comment looks misleading. This is the test for after_cancel() which doesn't raise a TclError.
Actually I think that checking that root.tk.call('after', 'info', 'spam') raises a TclError is not needed. Using this command in after_cancel() is an implementation detail.
|
|
||
| def test_after_cancel(self): | ||
| root = self.root | ||
| timer1 = root.after(5000, lambda: 'break') |
There was a problem hiding this comment.
Make commands having a side effect (for example adding an item to the list) and check that after canceling events and calling update() they are not executed.
There was a problem hiding this comment.
I made a counter within a callback function. Is that OK or is a list a better solution?
| (script, _) = root.tk.splitlist(root.tk.call('after', 'info', timer1)) | ||
| self.assertIn(script, root._tclCommands) | ||
| root.after_cancel(timer1) | ||
| self.assertNotIn(script, root._tclCommands) |
There was a problem hiding this comment.
Here root.tk.call(script) should raise a TclError and shouldn't have a side effect.
There was a problem hiding this comment.
Thanks! This is very helpful in my understanding.
| @@ -0,0 +1 @@ | |||
| :mod:`tkinter` change handling of ``None`` parameter call to after_cancel. | |||
There was a problem hiding this comment.
Could you please provide more useful information for readers? Like "after_cancel(None) now is error instead of canceling the first scheduled function."
And please add "Patch by your name."
|
Thanks @csabella for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6, 3.7. |
…e. (pythonGH-5701) (cherry picked from commit 74382a3) Co-authored-by: Cheryl Sabella <[email protected]>
|
GH-5972 is a backport of this pull request to the 3.7 branch. |
|
Sorry, @csabella and @serhiy-storchaka, I could not cleanly backport this to |
…e. (pythonGH-5701) (cherry picked from commit 74382a3) Co-authored-by: Cheryl Sabella <[email protected]>
|
GH-5973 is a backport of this pull request to the 3.6 branch. |
…e. (GH-5701) (cherry picked from commit 74382a3) Co-authored-by: Cheryl Sabella <[email protected]>
…e. (GH-5701) (cherry picked from commit 74382a3) Co-authored-by: Cheryl Sabella <[email protected]>
|
@serhiy-storchaka Would you like me to cherry pick this to 2.7? |
|
Yes, it would be nice. |
…e. (pythonGH-5701) (cherry picked from commit 74382a3)
|
GH-6620 is a backport of this pull request to the 2.7 branch. |
https://bugs.python.org/issue32857