summaryrefslogtreecommitdiffstats
path: root/Lib/datetime.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-08-04 09:38:46 (GMT)
committerGitHub <noreply@github.com>2019-08-04 09:38:46 (GMT)
commit17e52649c0e7e9389f1cc2444a53f059e24e6bca (patch)
tree2cfdcdaefd375aaf93ef6973f507ffb768ee5472 /Lib/datetime.py
parent5c72badd06a962fe0018ceb9916f3ae66314ea8e (diff)
downloadcpython-17e52649c0e7e9389f1cc2444a53f059e24e6bca.zip
cpython-17e52649c0e7e9389f1cc2444a53f059e24e6bca.tar.gz
cpython-17e52649c0e7e9389f1cc2444a53f059e24e6bca.tar.bz2
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.
Diffstat (limited to 'Lib/datetime.py')
-rw-r--r--Lib/datetime.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/Lib/datetime.py b/Lib/datetime.py
index e35ee05..d4c7a1f 100644
--- a/Lib/datetime.py
+++ b/Lib/datetime.py
@@ -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)