From c5304ee2bbff4fc0e6ae5cf312094ed13ae2c610 Mon Sep 17 00:00:00 2001 From: MinRK Date: Tue, 13 Nov 2012 11:43:06 -0800 Subject: [PATCH 1/3] check `ret is False` in Timer._on_timer The docstring states: > Functions can return False if they should not be called any more. Cleanup commit 2f11dee changed this logic, so any return value whose boolean interpretation is False (e.g. None) would be unregistered. fixes #1492 --- lib/matplotlib/backend_bases.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 3ef05b0aa12b..5c250228cf4f 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -1123,7 +1123,7 @@ def _on_timer(self): ''' for func, args, kwargs in self.callbacks: ret = func(*args, **kwargs) - if not ret: + if ret is False: self.callbacks.remove((func, args, kwargs)) if len(self.callbacks) == 0: From 2ac78c7773961a51015e59a92b006594c937e746 Mon Sep 17 00:00:00 2001 From: MinRK Date: Tue, 13 Nov 2012 12:11:10 -0800 Subject: [PATCH 2/3] add comment to protect against future 'cleanup' of `if ret is False` --- lib/matplotlib/backend_bases.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 5c250228cf4f..e16d21378f2e 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -1123,6 +1123,8 @@ def _on_timer(self): ''' for func, args, kwargs in self.callbacks: ret = func(*args, **kwargs) + # docstring above explains why we use `if ret is False` here, + # instead of `if not ret`. if ret is False: self.callbacks.remove((func, args, kwargs)) From 73371b04166640caf9fc92eec26d5b120308490a Mon Sep 17 00:00:00 2001 From: MinRK Date: Thu, 15 Nov 2012 10:52:24 -0800 Subject: [PATCH 3/3] use ret == False instead of ret is False per review --- lib/matplotlib/backend_bases.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index e16d21378f2e..c6814e9f3019 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -1118,14 +1118,14 @@ def _timer_set_single_shot(self): def _on_timer(self): ''' Runs all function that have been registered as callbacks. Functions - can return False if they should not be called any more. If there + can return False (or 0) if they should not be called any more. If there are no callbacks, the timer is automatically stopped. ''' for func, args, kwargs in self.callbacks: ret = func(*args, **kwargs) - # docstring above explains why we use `if ret is False` here, + # docstring above explains why we use `if ret == False` here, # instead of `if not ret`. - if ret is False: + if ret == False: self.callbacks.remove((func, args, kwargs)) if len(self.callbacks) == 0: