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

gcruz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 1babf6314aabcb38d05b83593b73eaceb606d8a6
Author: Dave Brondsema <[email protected]>
AuthorDate: Fri Aug 5 17:33:43 2022 -0400

    has_access() works with == not just is/bool checks
---
 Allura/allura/lib/utils.py        | 9 ++++++++-
 Allura/allura/tests/test_utils.py | 4 ++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index 63045c259..28a621038 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -389,7 +389,6 @@ class AntiSpam:
 
 
 class TruthyCallable:
-
     '''
     Wraps a callable to make it truthy in a boolean context.
 
@@ -405,6 +404,14 @@ class TruthyCallable:
     def __bool__(self):
         return self.callable()
 
+    def __eq__(self, other):
+        if other is True and bool(self):
+            return True
+        elif other is False and not bool(self):
+            return True
+        else:
+            return NotImplemented
+
 
 class TransformedDict(collections.MutableMapping):
 
diff --git a/Allura/allura/tests/test_utils.py 
b/Allura/allura/tests/test_utils.py
index bc7359578..8a1231479 100644
--- a/Allura/allura/tests/test_utils.py
+++ b/Allura/allura/tests/test_utils.py
@@ -190,6 +190,10 @@ class TestTruthyCallable(unittest.TestCase):
         assert bool(true_predicate) is True
         assert bool(false_predicate) is False
 
+        t, f = True, False  # use variables because '== True' would generate 
warnings, and we do want '==' not 'is'
+        assert true_predicate == t
+        assert false_predicate == f
+
 
 class TestCaseInsensitiveDict(unittest.TestCase):
 

Reply via email to