mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
bpo-37685: Fixed __eq__, __lt__ etc implementations in some classes. (GH-14952)
They now return NotImplemented for unsupported type of the other operand.
This commit is contained in:
parent
4c69be22df
commit
662db125cd
23 changed files with 1295 additions and 1150 deletions
|
@ -313,31 +313,38 @@ class DateTime:
|
|||
s = self.timetuple()
|
||||
o = other.timetuple()
|
||||
else:
|
||||
otype = (hasattr(other, "__class__")
|
||||
and other.__class__.__name__
|
||||
or type(other))
|
||||
raise TypeError("Can't compare %s and %s" %
|
||||
(self.__class__.__name__, otype))
|
||||
s = self
|
||||
o = NotImplemented
|
||||
return s, o
|
||||
|
||||
def __lt__(self, other):
|
||||
s, o = self.make_comparable(other)
|
||||
if o is NotImplemented:
|
||||
return NotImplemented
|
||||
return s < o
|
||||
|
||||
def __le__(self, other):
|
||||
s, o = self.make_comparable(other)
|
||||
if o is NotImplemented:
|
||||
return NotImplemented
|
||||
return s <= o
|
||||
|
||||
def __gt__(self, other):
|
||||
s, o = self.make_comparable(other)
|
||||
if o is NotImplemented:
|
||||
return NotImplemented
|
||||
return s > o
|
||||
|
||||
def __ge__(self, other):
|
||||
s, o = self.make_comparable(other)
|
||||
if o is NotImplemented:
|
||||
return NotImplemented
|
||||
return s >= o
|
||||
|
||||
def __eq__(self, other):
|
||||
s, o = self.make_comparable(other)
|
||||
if o is NotImplemented:
|
||||
return NotImplemented
|
||||
return s == o
|
||||
|
||||
def timetuple(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue