Let equal Timestamps not be unequal
Make the result of Timestamp(x) != Timestamp(x) be False. In python 2.7 this requires the __ne__ method to be defined [1]. "The truth of x==y does not imply that x!=y is false." The functools.total_ordering decorator does not autocreate a __ne__ method. In python 3 the __ne__ method is not required [2]. "By default, __ne__() delegates to __eq__() and inverts the result". This patch puts back the __ne__ method removed in [3]. Whilst no tests fail on master with python2.7, they do on this patch [4] and it seems dangerous to have this absurd behaviour lurking. [1] https://docs.python.org/2/reference/datamodel.html#object.__ne__ [2] https://docs.python.org/3.4/reference/datamodel.html#object.__ne__ [3] Change-Id: Id26777ac2c780316ff10ef7d954c48cc1fd480b5 [4] Change-Id: Ia597cd460bb5fd40aa92e886e3e18a7542603d01 Change-Id: I01fbfa310df3c74390f8e8c2e9ffff81bbf05e47
This commit is contained in:
parent
5ec586bd34
commit
a1776b9c1f
@ -847,6 +847,11 @@ class Timestamp(object):
|
||||
other = Timestamp(other)
|
||||
return self.internal == other.internal
|
||||
|
||||
def __ne__(self, other):
|
||||
if not isinstance(other, Timestamp):
|
||||
other = Timestamp(other)
|
||||
return self.internal != other.internal
|
||||
|
||||
def __lt__(self, other):
|
||||
if not isinstance(other, Timestamp):
|
||||
other = Timestamp(other)
|
||||
|
@ -287,6 +287,10 @@ class TestTimestamp(unittest.TestCase):
|
||||
for value in test_values:
|
||||
self.assertTrue(value != ts)
|
||||
|
||||
self.assertIs(True, utils.Timestamp(ts) == ts) # sanity
|
||||
self.assertIs(False, utils.Timestamp(ts) != utils.Timestamp(ts))
|
||||
self.assertIs(False, utils.Timestamp(ts) != ts)
|
||||
|
||||
def test_no_force_internal_no_offset(self):
|
||||
"""Test that internal is the same as normal with no offset"""
|
||||
with mock.patch('swift.common.utils.FORCE_INTERNAL', new=False):
|
||||
|
Loading…
Reference in New Issue
Block a user