Skip to content

Commit 714161c

Browse files
author
Alex Gaynor
committed
Fix != operations on lazy objects.
1 parent 59d127e commit 714161c

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

django/utils/functional.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ def __repr__(self):
346346
# care about this (especially in equality tests)
347347
__class__ = property(new_method_proxy(operator.attrgetter("__class__")))
348348
__eq__ = new_method_proxy(operator.eq)
349+
__ne__ = new_method_proxy(operator.ne)
349350
__hash__ = new_method_proxy(hash)
350351
__bool__ = new_method_proxy(bool) # Python 3
351352
__nonzero__ = __bool__ # Python 2

tests/utils_tests/test_simplelazyobject.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,12 @@ def trace_func(frame, event, arg):
152152
SimpleLazyObject(None)
153153
finally:
154154
sys.settrace(old_trace_func)
155+
156+
def test_not_equal(self):
157+
lazy1 = SimpleLazyObject(lambda: 2)
158+
lazy2 = SimpleLazyObject(lambda: 2)
159+
lazy3 = SimpleLazyObject(lambda: 3)
160+
self.assertEqual(lazy1, lazy2)
161+
self.assertNotEqual(lazy1, lazy3)
162+
self.assertTrue(lazy1 != lazy3)
163+
self.assertFalse(lazy1 != lazy2)

0 commit comments

Comments
 (0)