diff options
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/deprecation.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/django/utils/deprecation.py b/django/utils/deprecation.py index 905bbc4f6d..70216e8c5b 100644 --- a/django/utils/deprecation.py +++ b/django/utils/deprecation.py @@ -79,3 +79,33 @@ class DeprecationInstanceCheck(type): self.deprecation_warning, 2 ) return super(DeprecationInstanceCheck, self).__instancecheck__(instance) + + +class CallableBool: + """ + An boolean-like object that is also callable for backwards compatibility. + """ + do_not_call_in_templates = True + + def __init__(self, value): + self.value = value + + def __bool__(self): + return self.value + + def __call__(self): + warnings.warn( + "Using user.is_authenticated() and user.is_anonymous() as a method " + "is deprecated. Remove the parentheses to use it as an attribute.", + RemovedInDjango20Warning, stacklevel=2 + ) + return self.value + + def __nonzero__(self): # Python 2 compatibility + return self.value + + def __repr__(self): + return 'CallableBool(%r)' % self.value + +CallableFalse = CallableBool(False) +CallableTrue = CallableBool(True) |
