Refect(Core): Improve error catch in apply and apply_on_last_level

This commit is contained in:
2018-11-21 15:54:07 +01:00
parent fe52d9b346
commit 8933359945
4 changed files with 23 additions and 38 deletions

View File

@@ -100,26 +100,9 @@ x^7
from .expression import Expression
if __name__ == "__main__":
e = Expression.from_str("2x^2+2x+3x")
print(e._tree.map_on_leaf(lambda x:(x,)))
for _ in range(5):
print("-"*10)
e = e._optimize()
try:
print(e._tree.map_on_leaf(lambda x:(x,)))
except AttributeError:
print(e)
e = e._typing()
try:
print(e._tree.map_on_leaf(lambda x:(x,)))
except AttributeError:
print(e)
e = e._compute()
try:
print(e._tree.map_on_leaf(lambda x:(x,)))
except AttributeError:
print(e)
e = Expression.from_str("2+3/4")
e_simplified = e.simplify()
print(e_simplified)
# -----------------------------
# Reglages pour 'vim'

View File

@@ -163,11 +163,9 @@ class Expression(object):
> <class 'mapytex.calculus.core.MO.fraction.MOFraction'>
"""
try:
t = self._tree.apply_on_last_level(typing)
except (TypingError, NotImplementedError, AttributeError):
return Expression(self._tree.apply(typing))
except AttributeError:
return self
else:
return Expression(t)._typing()
def _compute(self):
"""" Compute one step of self