Skip to content

Conversation

@lverweijen
Copy link
Owner

Some simplifications to Route

  • Add more unit tests.
  • Handle some edge-cases correctly. Mostly when route has only 1 of 0 anchors.
  • Always store route._ancestors_levels instead of calculating these lazily (a form of premature optimization).
  • Merge Route and NodesView classes (simplify api). Make route.nodes return route for backwards compatibility.
  • Make anchors return a tuple instead of an AnchorView. There are typically only a few anchors, so no need to make this more complicated than needed.
  • Make reversed(route.edges) return edges in parent-child order for consistenty with iter(route.edges).

@lverweijen
Copy link
Owner Author

lverweijen commented Jul 23, 2025

Some ideas for later:

  • Make node.path.edges work. This would provide a nice consistency with route.edges. node.path could even implement some kind of BaseRoute interface.
  • Make route.add_anchor(anchor) accept a second optional argument in which a precalculated path can be given.
  • Make new_route = Route(old_route) work. It should recalculate the route. It would be the same as new_route = Route(*old_route.anchors). This can help if the tree changed in the mean time.
  • Make route = Route(node.path) work, except I don't know if a Route object has much benefit over using a list.
  • Make route_combined = route_a + route_b work. The benefit over a list is that this should connect the endpoints of route_a and route_b in the result. Multiplication could also work. It seems intuitive to me, but I don't see many cases where this can be used.
  • Make route.reverse() work. Easy to implement, but no clear benefit over just storing the route in a list and reversing that.

Edit: Thinking some more about addition. If implemented, it should probably require the endpoints to be the same, so route_a should end where route_b begins. Otherwise, raise ValueError. Then forget about multiplication.

@lverweijen lverweijen merged commit 34a1a34 into main Aug 4, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants