Feat: tokenify for everything!

This commit is contained in:
2019-07-17 09:25:12 +02:00
parent a32b684b6b
commit d75fd4c4cf
2 changed files with 117 additions and 33 deletions

View File

@@ -91,6 +91,12 @@ class MOnumber(Atom):
>>> MOnumber(Decimal("-23.3"))
<MOnumber - 23.3>
Or directly passe a decimal string
>>> MOnumber("23.3")
<MOnumber 23.3>
>>> MOnumber("-23.3")
<MOnumber - 23.3>
MOnumber initialisation is idempotent
>>> a = MOnumber(23)
@@ -100,7 +106,7 @@ class MOnumber(Atom):
>>> MOnumber("a")
Traceback (most recent call last):
...
mapytex.calculus.core.MO.exceptions.MOError: ('The value of an MOnumber need to be a int, a float or a Decimal', "(got <class 'str'>)")
mapytex.calculus.core.MO.exceptions.MOError: ('The value of an MOnumber need to be a int, a float, a Decimal or a decimal string', "(got <class 'str'>)")
Atoms specific property and methods
@@ -122,10 +128,15 @@ class MOnumber(Atom):
elif isinstance(value, float):
Atom.__init__(self, Decimal(value))
else:
raise MOError(
"The value of an MOnumber need to be a int, a float or a Decimal",
f"(got {type(value)})",
)
try:
float(value)
except (ValueError, TypeError):
raise MOError(
"The value of an MOnumber need to be a int, a float, a Decimal or a decimal string",
f"(got {type(value)})",
)
else:
Atom.__init__(self, Decimal(value))
self._signature = "scalar"