1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

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.
This commit is contained in:
ElizabethU
2019-09-02 19:09:31 -07:00
committed by Mariusz Felisiak
parent 6475e6318c
commit 54ea290e5b
20 changed files with 71 additions and 33 deletions

View File

@@ -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):