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

@@ -7,7 +7,7 @@
# Distributed under terms of the MIT license.
"""
Computing with MO
Typing with MO
"""
from .exceptions import TypingError
@@ -35,7 +35,8 @@ OPERATIONS = {
"^": power,
}
def typing(node, left_v, right_v):
def typing(node, left_v, right_v,\
raiseTypingError = True):
"""
Typing a try base on his root node
@@ -46,11 +47,12 @@ def typing(node, left_v, right_v):
try:
operation = OPERATIONS[node]
except KeyError:
raise TypingError(f"Unknown operation ({node}) in typing")
try:
return operation(left_v, right_v)
except NotImplementedError:
raise TypingError(f"Can't create new MO with {node}, {type(left_v)} and {type(right_v)}")
raise NotImplementedError(f"Unknown operation ({node}) in typing")
return operation(left_v, right_v)
# try:
# return operation(left_v, right_v)
# except NotImplementedError:
# raise TypingError(f"Can't create new MO with {node}, {type(left_v)} and {type(right_v)}")
def typing_capacities(node):
""" Test an operation through all MOs