Refect(Core): Improve error catch in apply and apply_on_last_level
This commit is contained in:
@@ -330,8 +330,6 @@ class Tree(object):
|
||||
try:
|
||||
left_applied = self.left_value.\
|
||||
apply_on_last_level(function)
|
||||
except NotImplementedError:
|
||||
left_applied = self.left_value
|
||||
except AttributeError:
|
||||
left_applied = self.left_value
|
||||
left_is_leaf = 1
|
||||
@@ -340,14 +338,15 @@ class Tree(object):
|
||||
try:
|
||||
right_applied = self.right_value.\
|
||||
apply_on_last_level(function)
|
||||
except NotImplementedError:
|
||||
right_applied = self.right_value
|
||||
except AttributeError:
|
||||
right_applied = self.right_value
|
||||
right_is_leaf = 1
|
||||
|
||||
if left_is_leaf and right_is_leaf:
|
||||
return function(self.node, left_applied, right_applied)
|
||||
try:
|
||||
return function(self.node, left_applied, right_applied)
|
||||
except NotImplementedError:
|
||||
return Tree(self.node, left_applied, right_applied)
|
||||
else:
|
||||
return Tree(self.node, left_applied, right_applied)
|
||||
|
||||
@@ -389,7 +388,10 @@ class Tree(object):
|
||||
except AttributeError:
|
||||
right_value = self.right_value
|
||||
|
||||
return function(self.node, left_value, right_value)
|
||||
try:
|
||||
return function(self.node, left_value, right_value)
|
||||
except NotImplementedError:
|
||||
return Tree(self.node, left_value, right_value)
|
||||
|
||||
def get_leafs(self, callback=lambda x:x):
|
||||
""" Generator which yield all the leaf value of the tree.
|
||||
@@ -843,7 +845,7 @@ class Tree(object):
|
||||
self.left_value,
|
||||
self.right_value.short_branch)
|
||||
return Tree(self.node, new_left, new_right).balance(exclude_nodes)
|
||||
|
||||
|
||||
try:
|
||||
left_v = self.left_value.balance(exclude_nodes)
|
||||
except AttributeError:
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user