summaryrefslogtreecommitdiff
path: root/django/template/context.py
diff options
context:
space:
mode:
authorElizabethU <elizabeth.uselton@gmail.com>2019-09-02 19:09:31 -0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-10-01 17:58:19 +0200
commit54ea290e5bbd19d87bd8dba807738eeeaf01a362 (patch)
treed83c186bde9f50faa13840e6ee227e3bb1e02ad6 /django/template/context.py
parent6475e6318c970359a2f02798910a917229ee17d7 (diff)
Fixed #30651 -- Made __eq__() methods return NotImplemented for not implemented comparisons.
Changed __eq__ to return NotImplemented instead of False if compared to an object of the same type, as is recommended by the Python data model reference. Now these models can be compared to ANY (or other objects with __eq__ overwritten) without returning False automatically.
Diffstat (limited to 'django/template/context.py')
-rw-r--r--django/template/context.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/django/template/context.py b/django/template/context.py
index 8f349a3a96..f0a0cf2a00 100644
--- a/django/template/context.py
+++ b/django/template/context.py
@@ -124,12 +124,10 @@ class BaseContext:
"""
Compare two contexts by comparing theirs 'dicts' attributes.
"""
- return (
- isinstance(other, BaseContext) and
- # because dictionaries can be put in different order
- # we have to flatten them like in templates
- self.flatten() == other.flatten()
- )
+ if not isinstance(other, BaseContext):
+ return NotImplemented
+ # flatten dictionaries because they can be put in a different order.
+ return self.flatten() == other.flatten()
class Context(BaseContext):