Fixed #27154 -- Allowed comparing CallableBool with bitwise or.
Thanks Tim for the review.
This commit is contained in:
parent
b961b51eaf
commit
b7fb608142
|
@ -116,6 +116,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