mirror of
https://github.com/python/cpython.git
synced 2025-10-06 15:11:58 +00:00
bpo-37685: Fixed comparisons of datetime.timedelta and datetime.timezone. (GH-14996)
There was a discrepancy between the Python and C implementations. Add singletons ALWAYS_EQ, LARGEST and SMALLEST in test.support to test mixed type comparison.
This commit is contained in:
parent
5c72badd06
commit
17e52649c0
7 changed files with 107 additions and 84 deletions
|
@ -739,25 +739,25 @@ class timedelta:
|
|||
if isinstance(other, timedelta):
|
||||
return self._cmp(other) <= 0
|
||||
else:
|
||||
_cmperror(self, other)
|
||||
return NotImplemented
|
||||
|
||||
def __lt__(self, other):
|
||||
if isinstance(other, timedelta):
|
||||
return self._cmp(other) < 0
|
||||
else:
|
||||
_cmperror(self, other)
|
||||
return NotImplemented
|
||||
|
||||
def __ge__(self, other):
|
||||
if isinstance(other, timedelta):
|
||||
return self._cmp(other) >= 0
|
||||
else:
|
||||
_cmperror(self, other)
|
||||
return NotImplemented
|
||||
|
||||
def __gt__(self, other):
|
||||
if isinstance(other, timedelta):
|
||||
return self._cmp(other) > 0
|
||||
else:
|
||||
_cmperror(self, other)
|
||||
return NotImplemented
|
||||
|
||||
def _cmp(self, other):
|
||||
assert isinstance(other, timedelta)
|
||||
|
@ -1316,25 +1316,25 @@ class time:
|
|||
if isinstance(other, time):
|
||||
return self._cmp(other) <= 0
|
||||
else:
|
||||
_cmperror(self, other)
|
||||
return NotImplemented
|
||||
|
||||
def __lt__(self, other):
|
||||
if isinstance(other, time):
|
||||
return self._cmp(other) < 0
|
||||
else:
|
||||
_cmperror(self, other)
|
||||
return NotImplemented
|
||||
|
||||
def __ge__(self, other):
|
||||
if isinstance(other, time):
|
||||
return self._cmp(other) >= 0
|
||||
else:
|
||||
_cmperror(self, other)
|
||||
return NotImplemented
|
||||
|
||||
def __gt__(self, other):
|
||||
if isinstance(other, time):
|
||||
return self._cmp(other) > 0
|
||||
else:
|
||||
_cmperror(self, other)
|
||||
return NotImplemented
|
||||
|
||||
def _cmp(self, other, allow_mixed=False):
|
||||
assert isinstance(other, time)
|
||||
|
@ -2210,9 +2210,9 @@ class timezone(tzinfo):
|
|||
return (self._offset, self._name)
|
||||
|
||||
def __eq__(self, other):
|
||||
if type(other) != timezone:
|
||||
return False
|
||||
return self._offset == other._offset
|
||||
if isinstance(other, timezone):
|
||||
return self._offset == other._offset
|
||||
return NotImplemented
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self._offset)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue