Skip to content

Commit

Permalink
Fix != operations on lazy objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Gaynor committed Apr 19, 2013
1 parent 59d127e commit 714161c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions django/utils/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ def __repr__(self):
# care about this (especially in equality tests)
__class__ = property(new_method_proxy(operator.attrgetter("__class__")))
__eq__ = new_method_proxy(operator.eq)
__ne__ = new_method_proxy(operator.ne)
__hash__ = new_method_proxy(hash)
__bool__ = new_method_proxy(bool) # Python 3
__nonzero__ = __bool__ # Python 2
Expand Down
9 changes: 9 additions & 0 deletions tests/utils_tests/test_simplelazyobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,12 @@ def trace_func(frame, event, arg):
SimpleLazyObject(None)
finally:
sys.settrace(old_trace_func)

def test_not_equal(self):
lazy1 = SimpleLazyObject(lambda: 2)
lazy2 = SimpleLazyObject(lambda: 2)
lazy3 = SimpleLazyObject(lambda: 3)
self.assertEqual(lazy1, lazy2)
self.assertNotEqual(lazy1, lazy3)
self.assertTrue(lazy1 != lazy3)
self.assertFalse(lazy1 != lazy2)

0 comments on commit 714161c

Please sign in to comment.