This is an automated email from the ASF dual-hosted git repository.

kentontaylor pushed a commit to branch kt/memoize-fix
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 330cda3e5621942f022a8fa83f21fb08fa08794a
Author: Kenton Taylor <[email protected]>
AuthorDate: Wed Feb 9 20:03:19 2022 +0000

    Allow memoize_cleanup to work with dicts or objects
---
 Allura/allura/lib/decorators.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/Allura/allura/lib/decorators.py b/Allura/allura/lib/decorators.py
index 7197748..406be72 100644
--- a/Allura/allura/lib/decorators.py
+++ b/Allura/allura/lib/decorators.py
@@ -176,11 +176,15 @@ def memoize(func, instance, args, kwargs):
 
 def memoize_cleanup(obj):
     """
-    Remove any _memoize_dic_* keys (if obj is a dict/obj hybrid) that were 
created by @memoize on methods
+    Remove any _memoize_dic_* keys that were created by @memoize on methods
     """
-    for k in list(obj.keys()):
+    attrs = obj.keys() if hasattr(obj, 'keys') else obj.__dir__()
+    for k in list(attrs):
         if k.startswith('_memoize_dic'):
-            del obj[k]
+            try:
+                del obj[k]
+            except TypeError:
+                delattr(obj, k)
 
 
 def memorable_forget():

Reply via email to