From 54ea290e5bbd19d87bd8dba807738eeeaf01a362 Mon Sep 17 00:00:00 2001 From: ElizabethU Date: Mon, 2 Sep 2019 19:09:31 -0700 Subject: 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. --- django/core/validators.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'django/core/validators.py') diff --git a/django/core/validators.py b/django/core/validators.py index 2e00ca3ff3..38345a844f 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -324,8 +324,9 @@ class BaseValidator: raise ValidationError(self.message, code=self.code, params=params) def __eq__(self, other): + if not isinstance(other, self.__class__): + return NotImplemented return ( - isinstance(other, self.__class__) and self.limit_value == other.limit_value and self.message == other.message and self.code == other.code -- cgit v1.3