Compare commits

...

2 Commits

Author SHA1 Message Date
Bertrand Benjamin 1a20e6927d Feat: remove __txt__ and __tex__
continuous-integration/drone/push Build is passing Details
2020-12-12 22:10:53 +01:00
Bertrand Benjamin 7649928be8 Fix: clean __str__ method for token 2020-12-12 22:10:53 +01:00
1 changed files with 4 additions and 20 deletions

View File

@ -44,7 +44,7 @@ class Token(object):
def explain(self): def explain(self):
""" Yield every calculus step which have lead to self """ Yield every calculus step which have lead to self
:example: :example:
>>> from mapytex.calculus.API import Expression >>> from mapytex.calculus.API import Expression
>>> e = Expression.from_str("2+3*4") >>> e = Expression.from_str("2+3*4")
@ -64,25 +64,10 @@ class Token(object):
yield self yield self
def __repr__(self): def __repr__(self):
return f"<{self.__class__.__name__} {self.__txt__}>" return f"<{self.__class__.__name__} {renders['txt'](self._mo)}>"
def __str__(self): def __str__(self):
if self.RENDER == "tex": return renders[self.RENDER](self._mo)
return self.__tex__
elif self.RENDER == "txt":
return self.__txt__
else:
raise ValueError(f"Unknow render {self.RENDER}")
# return renders[self.RENDER](self._mo)
@property
def __txt__(self):
return self._mo.__txt__
@property
def __tex__(self):
return self._mo.__tex__
@property @property
def raw(self): def raw(self):
@ -265,7 +250,6 @@ class Token(object):
""" """
return self._operate(other, "^") return self._operate(other, "^")
def _roperate(self, other, operation): def _roperate(self, other, operation):
""" Make a operation between 2 Tokens """ """ Make a operation between 2 Tokens """
from ..expression import Expression from ..expression import Expression
@ -315,6 +299,7 @@ class Token(object):
<Linear x - 3> <Linear x - 3>
""" """
return self._roperate(other, "-") return self._roperate(other, "-")
def __rmul__(self, other): def __rmul__(self, other):
""" Multiply 2 Tokens or a Token and a Expression """ Multiply 2 Tokens or a Token and a Expression
@ -342,7 +327,6 @@ class Token(object):
""" """
return self._roperate(other, "/") return self._roperate(other, "/")
def _get_soul(self, other=None): def _get_soul(self, other=None):
""" Get the builtin soul of self or other """ """ Get the builtin soul of self or other """
if isinstance(other, Token): if isinstance(other, Token):