mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +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:
parent
6475e6318c
commit
54ea290e5b
20 changed files with 71 additions and 33 deletions
|
@ -1,3 +1,5 @@
|
|||
from unittest import mock
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import IntegrityError, connection, models
|
||||
from django.db.models.constraints import BaseConstraint
|
||||
|
@ -39,6 +41,7 @@ class CheckConstraintTests(TestCase):
|
|||
models.CheckConstraint(check=check1, name='price'),
|
||||
models.CheckConstraint(check=check1, name='price'),
|
||||
)
|
||||
self.assertEqual(models.CheckConstraint(check=check1, name='price'), mock.ANY)
|
||||
self.assertNotEqual(
|
||||
models.CheckConstraint(check=check1, name='price'),
|
||||
models.CheckConstraint(check=check1, name='price2'),
|
||||
|
@ -102,6 +105,10 @@ class UniqueConstraintTests(TestCase):
|
|||
models.UniqueConstraint(fields=['foo', 'bar'], name='unique'),
|
||||
models.UniqueConstraint(fields=['foo', 'bar'], name='unique'),
|
||||
)
|
||||
self.assertEqual(
|
||||
models.UniqueConstraint(fields=['foo', 'bar'], name='unique'),
|
||||
mock.ANY,
|
||||
)
|
||||
self.assertNotEqual(
|
||||
models.UniqueConstraint(fields=['foo', 'bar'], name='unique'),
|
||||
models.UniqueConstraint(fields=['foo', 'bar'], name='unique2'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue