From 7c57f5cf8cd10b69d0c76ba97ab048ccc2917c55 Mon Sep 17 00:00:00 2001 From: Olexander Yermakov Date: Wed, 31 Aug 2016 11:07:30 +0300 Subject: [PATCH] [1.10.x] Fixed #27154 -- Allowed comparing CallableBool with bitwise or. Thanks Tim for the review. Backport of b7fb608142a0be568bc5dce952de5e6aefc2488c from master --- django/utils/deprecation.py | 3 +++ docs/releases/1.10.1.txt | 2 +- tests/utils_tests/test_deprecation.py | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/django/utils/deprecation.py b/django/utils/deprecation.py index 0a0dd216da..dd1345757e 100644 --- a/django/utils/deprecation.py +++ b/django/utils/deprecation.py @@ -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) diff --git a/docs/releases/1.10.1.txt b/docs/releases/1.10.1.txt index 719f536b29..6dbf40de02 100644 --- a/docs/releases/1.10.1.txt +++ b/docs/releases/1.10.1.txt @@ -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`). diff --git a/tests/utils_tests/test_deprecation.py b/tests/utils_tests/test_deprecation.py index 41627ce1b3..7732dbc62b 100644 --- a/tests/utils_tests/test_deprecation.py +++ b/tests/utils_tests/test_deprecation.py @@ -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)