Feat: to_be_token decorator and force token to be Integer when it's

possible
This commit is contained in:
2019-07-17 09:49:50 +02:00
parent d75fd4c4cf
commit 204fdf755b
3 changed files with 62 additions and 21 deletions

View File

@@ -123,10 +123,13 @@ class MOnumber(Atom):
"""
if isinstance(value, Atom) and isinstance(value.value, (int, Decimal, float)):
Atom.__init__(self, value.value)
elif isinstance(value, (int, Decimal)):
elif isinstance(value, (float, Decimal)):
if int(value) == value:
Atom.__init__(self, int(value))
else:
Atom.__init__(self, Decimal(value))
elif isinstance(value, int):
Atom.__init__(self, value)
elif isinstance(value, float):
Atom.__init__(self, Decimal(value))
else:
try:
float(value)
@@ -165,7 +168,7 @@ class MOnumber(Atom):
>>> MOnumber(-3).__tex__
'- 3'
"""
if self.value > 0:
if self.value >= 0:
return str(self.value)
return f"- {abs(self.value)}"