diff --git a/mapytex/calculus/core/MO/mo.py b/mapytex/calculus/core/MO/mo.py index b3637f3..b15242f 100644 --- a/mapytex/calculus/core/MO/mo.py +++ b/mapytex/calculus/core/MO/mo.py @@ -67,7 +67,22 @@ class MO(object): @classmethod def factory(cls, value): - """ Factory to ensure that a value is a MO before using it """ + """ Factory to ensure that a value is a MO before using it + + Idempotent?? + + >>> MO.factory("x") + + >>> MO.factory(2) + + >>> MO.factory(2.3) + + >>> MO.factory(Decimal("2.3")) + + >>> x = MO.factory("x") + >>> MO.factory(x) + + """ if isinstance(value, str): return MOstr(value) elif isinstance(value, int) \ @@ -77,7 +92,8 @@ class MO(object): elif isinstance(value, MO): return value - return MO(value) + raise MOError("Can't convert it into a MO." + f"Need str, int, Decimal, float or MO, got {value}") def __repr__(self): return f"<{self.__class__.__name__} {self.__txt__}>"