Add __ne__ built-in function

In Python 3 __ne__ by default delegates to __eq__ and inverts the
result, but in Python 2 they urge you to define __ne__ when you
define __eq__ for it to work properly [1].There are no implied
relationships among the comparison operators. The truth of x==y
does not imply that x!=y is false. Accordingly, when defining __eq__(),
one should also define __ne__() so that the operators will behave
as expected.
[1]https://docs.python.org/2/reference/datamodel.html#object.__ne__

Change-Id: I2eecd9d90a3a6ba09917f27f2f8568a42beb58d1
This commit is contained in:
gecong1973 2016-09-20 10:26:54 +08:00 committed by Frédéric Guillot
parent 6a3812cf1b
commit 22c6251c2a

View File

@ -91,6 +91,9 @@ class DateMatcher(object):
def __eq__(self, other):
return other == self.date
def __ne__(self, other):
return not self.__eq__(other)
def a_date_matching(date_string):
return DateMatcher(datetime.strptime(date_string, "%Y-%m-%d %H:%M:%S.%f"))