From 3ab55c1a8a58ae6d6791cafbcefaf224d01ff314 Mon Sep 17 00:00:00 2001 From: Reto Aebersold Date: Tue, 4 Oct 2016 05:44:19 -0600 Subject: [PATCH] Fixed #27309 -- Added CallableBool.__hash__(). --- django/utils/deprecation.py | 3 +++ docs/releases/1.10.3.txt | 3 ++- tests/utils_tests/test_deprecation.py | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/django/utils/deprecation.py b/django/utils/deprecation.py index 6fc27a8edd..ce3c90aa77 100644 --- a/django/utils/deprecation.py +++ b/django/utils/deprecation.py @@ -119,6 +119,9 @@ class CallableBool: def __or__(self, other): return bool(self.value or other) + def __hash__(self): + return hash(self.value) + CallableFalse = CallableBool(False) CallableTrue = CallableBool(True) diff --git a/docs/releases/1.10.3.txt b/docs/releases/1.10.3.txt index 9900080b8f..2560b1db00 100644 --- a/docs/releases/1.10.3.txt +++ b/docs/releases/1.10.3.txt @@ -9,4 +9,5 @@ Django 1.10.3 fixes several bugs in 1.10.2. Bugfixes ======== -* ... +* Allowed ``User.is_authenticated`` and ``User.is_anonymous`` properties to be + tested for ``set`` membership (:ticket:`27309`). diff --git a/tests/utils_tests/test_deprecation.py b/tests/utils_tests/test_deprecation.py index 7732dbc62b..56ba259a2f 100644 --- a/tests/utils_tests/test_deprecation.py +++ b/tests/utils_tests/test_deprecation.py @@ -25,3 +25,7 @@ class TestCallableBool(SimpleTestCase): self.assertIs(CallableTrue | False, True) self.assertIs(CallableFalse | True, True) self.assertFalse(CallableFalse | False, False) + + def test_set_membership(self): + self.assertIs(CallableTrue in {True}, True) + self.assertIs(CallableFalse not in {True}, True)