[1.10.x] Fixed #27154 -- Allowed comparing CallableBool with bitwise or.
Thanks Tim for the review.
Backport of b7fb608142
from master
This commit is contained in:
parent
c6c1d940c1
commit
7c57f5cf8c
|
@ -113,6 +113,9 @@ class CallableBool:
|
|||
def __ne__(self, other):
|
||||
return self.value != other
|
||||
|
||||
def __or__(self, other):
|
||||
return bool(self.value or other)
|
||||
|
||||
CallableFalse = CallableBool(False)
|
||||
CallableTrue = CallableBool(True)
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ Bugfixes
|
|||
doesn't return a result (:ticket:`26991`).
|
||||
|
||||
* Allowed ``User.is_authenticated`` and ``User.is_anonymous`` properties to be
|
||||
compared using ``==`` and ``!=`` (:ticket:`26988`).
|
||||
compared using ``==``, ``!=``, and ``|`` (:ticket:`26988`, :ticket:`27154`).
|
||||
|
||||
* Removed the broken ``BaseCommand.usage()`` method which was for
|
||||
``optparse`` support (:ticket:`27000`).
|
||||
|
|
|
@ -14,3 +14,14 @@ class TestCallableBool(SimpleTestCase):
|
|||
self.assertEqual(CallableFalse, False)
|
||||
self.assertFalse(CallableFalse != False) # noqa: E712
|
||||
self.assertNotEqual(CallableFalse, True)
|
||||
|
||||
def test_or(self):
|
||||
self.assertIs(CallableTrue | CallableTrue, True)
|
||||
self.assertIs(CallableTrue | CallableFalse, True)
|
||||
self.assertIs(CallableFalse | CallableTrue, True)
|
||||
self.assertIs(CallableFalse | CallableFalse, False)
|
||||
|
||||
self.assertIs(CallableTrue | True, True)
|
||||
self.assertIs(CallableTrue | False, True)
|
||||
self.assertIs(CallableFalse | True, True)
|
||||
self.assertFalse(CallableFalse | False, False)
|
||||
|
|
Loading…
Reference in New Issue