1
0
forked from ScoDoc/ScoDoc

Rich Comparisons for py3

This commit is contained in:
Emmanuel Viennet 2021-07-09 22:09:12 +02:00
parent 427eb169aa
commit aea498fa86
2 changed files with 48 additions and 4 deletions

View File

@ -188,11 +188,29 @@ class ddmmyyyy:
else:
return self.prev(self.weekday)
def __cmp__(self, other):
def __cmp__(self, other): # #py3 TODO à supprimer
"""return a negative integer if self < other,
zero if self == other, a positive integer if self > other"""
return int(self.time - other.time)
def __eq__(self, other):
return self.time == other.time
def __ne__(self, other):
return self.time != other.time
def __lt__(self, other):
return self.time < other.time
def __le__(self, other):
return self.time <= other.time
def __gt__(self, other):
return self.time > other.time
def __ge__(self, other):
return self.time >= other.time
def __hash__(self):
"we are immutable !"
return hash(self.time) ^ hash(str(self))

View File

@ -411,10 +411,14 @@ class ApoEtapeVDI:
def __str__(self):
return self.etape_vdi
def __cmp__(self, other):
def _cmp(self, other):
"""Test égalité de deux codes étapes.
Si le VDI des deux est spécifié, on l'utilise. Sinon, seul le code étape est pris en compte.
Donc V1RT == V1RT!111, V1RT!110 == V1RT, V1RT!77 != V1RT!78, ...
Compare the two objects x (=self) and y and return an integer according to
the outcome. The return value is negative if x < y, zero if x == y
and strictly positive if x > y.
"""
if other is None:
return -1
@ -422,9 +426,31 @@ class ApoEtapeVDI:
other = ApoEtapeVDI(other)
if self.vdi and other.vdi:
return cmp((self.etape, self.vdi), (other.etape, other.vdi))
x = (self.etape, self.vdi)
y = (other.etape, other.vdi)
else:
return cmp(self.etape, other.etape)
x = self.etape
y = other.etape
return (x > y) - (x < y)
def __eq__(self, other):
return self._cmp(other) == 0
def __ne__(self, other):
return self._cmp(other) != 0
def __lt__(self, other):
return self._cmp(other) < 0
def __le__(self, other):
return self._cmp(other) <= 0
def __gt__(self, other):
return self._cmp(other) > 0
def __ge__(self, other):
return self._cmp(other) >= 0
def split_etape_vdi(self, etape_vdi):
"""Etape Apogee can be stored as 'V1RT' or, including the VDI version,