def traverse(self, root: Base) -> Iterator[TraversalContext]:
stack: List[TraversalContext] = []
stack.append(TraversalContext(root))
while len(stack) > 0:
head = stack.pop()
current = head.current
active_rule = self._get_active_rule_or_default_rule(current)
if active_rule.should_return:
yield head
members_to_traverse = active_rule.get_members_to_traverse(current)
for child_prop in members_to_traverse:
try:
if child_prop in {"speckle_type", "units", "applicationId"}:
# debug: to avoid noisy exceptions,
# explicitly avoid checking ones we know will fail,
# this is not exhaustive
continue
if getattr(current, child_prop, None):
value = current[child_prop]
self._traverse_member_to_stack(stack, value, child_prop, head)
except KeyError:
# Unset application ids, and class variables like SpeckleType will
# throw when __getitem__ is called
pass