[master 1/1] Return the same object for repeated calls to __get__ (#1245423)

dashea installerbot-noreply at redhat.com
Fri Jul 24 19:05:49 UTC 2015


From: David Shea <dshea at redhat.com>

Having object.property be something different every time it's evaluated
makes things kind of weird.
---
 pyanaconda/ui/gui/utils.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/pyanaconda/ui/gui/utils.py b/pyanaconda/ui/gui/utils.py
index 676416f..9166606 100644
--- a/pyanaconda/ui/gui/utils.py
+++ b/pyanaconda/ui/gui/utils.py
@@ -255,6 +255,8 @@ def __init__(self, func):
             self._last_start = None
             self._timer_id = None
 
+            self._instance_map = {}
+
         @property
         def timer_active(self):
             """Whether there is a pending timer for this action."""
@@ -312,7 +314,10 @@ def __call__(self, *args, **kwargs):
         # instance of whatever is being decorated by returning a curried version
         # of ourself with the instance applied as the first argument.
         def __get__(self, instance, owner):
-            return functools.partial(self, instance)
+            if instance not in self._instance_map:
+                self._instance_map[instance] = functools.partial(self, instance)
+
+            return self._instance_map[instance]
 
     # Return TimedAction as the decorator function. The constructor will be
     # called with the function to be decorated as the argument, returning a


-- 
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/ea6566c9702749dfc0c1ca5525fa7f9cb15a5213


More information about the anaconda-patches mailing list