Skip to content

Commit

Permalink
Optimite visit() performance
Browse files Browse the repository at this point in the history
  • Loading branch information
mar10 committed Sep 22, 2024
1 parent 0a49431 commit 714cd82
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions nutree/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ def call_traversal_cb(fn: Callable, node: Node, memo: Any) -> False | None:
"""
try:
res = fn(node, memo)
if res is SkipBranch or isinstance(res, SkipBranch):

if res is None:
return None
elif res is SkipBranch or isinstance(res, SkipBranch):
return False
elif res is StopTraversal or isinstance(res, StopTraversal):
raise res
Expand All @@ -306,10 +309,10 @@ def call_traversal_cb(fn: Callable, node: Node, memo: Any) -> False | None:
elif res is StopIteration or isinstance(res, StopIteration):
# Converts wrong syntax in exception handler...
raise res
elif res is not None:
else:
raise ValueError(
"callback should not return values except for "
f"False, SkipBranch, or StopTraversal: {res!r}."
f"None, False, SkipBranch, or StopTraversal: {res!r}."
)
except SkipBranch:
return False
Expand Down

0 comments on commit 714cd82

Please sign in to comment.