Generic function for MO: __eq__ and __hash__
This commit is contained in:
parent
3f3e52cdf8
commit
3b59e0ffb0
@ -116,6 +116,15 @@ class MO(object):
|
||||
except AttributeError:
|
||||
return str(self.value)
|
||||
|
||||
def __hash__(self):
|
||||
return self.value.__hash__()
|
||||
|
||||
def __eq__(self, other):
|
||||
""" == a MOnumber """
|
||||
try:
|
||||
return self.value == other.value
|
||||
except AttributeError:
|
||||
return self.value == other
|
||||
|
||||
@total_ordering
|
||||
class MOnumber(MO):
|
||||
@ -254,13 +263,6 @@ class MOnumber(MO):
|
||||
except AttributeError:
|
||||
return other % self.value
|
||||
|
||||
def __eq__(self, other):
|
||||
""" == a MOnumber """
|
||||
try:
|
||||
return self.value == other.value
|
||||
except AttributeError:
|
||||
return self.value == other
|
||||
|
||||
def __lt__(self, other):
|
||||
""" < a MOnumber """
|
||||
try:
|
||||
@ -268,8 +270,6 @@ class MOnumber(MO):
|
||||
except AttributeError:
|
||||
return self.value < other
|
||||
|
||||
def __hash__(self):
|
||||
return self.value.__hash__()
|
||||
|
||||
class MOstr(MO):
|
||||
|
||||
@ -311,8 +311,13 @@ class MOstr(MO):
|
||||
if not val.isalpha():
|
||||
raise MOError(f"An MOstr should be initiate with a alpha string, got {val}")
|
||||
|
||||
MO.__init__(self, value)
|
||||
MO.__init__(self, val)
|
||||
self.is_scalar = False
|
||||
self._variable = val
|
||||
|
||||
@property
|
||||
def variable(self):
|
||||
return self._variable
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
|
Loading…
Reference in New Issue
Block a user