Repository navigation
fix: vertex.edges() and graph.edges() return a new container, not the internal one - #36
Closed
petercorke wants to merge 2 commits into
Closed
petercorke wants to merge 2 commits into
petercorke wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Both returned the object's own edge list/set, so v.edges().clear() emptied the vertex while the graph still counted the edges, leaving it inconsistent, and removing edges while iterating the result skipped some. They now return a copy, so a caller can do what it likes with the result. Audited first: inside pgraph the only consumer of vertex.edges() is degree (len only), and every call site in RTB, MVTB and spatialmath only iterates the result or takes its length; none mutates it. BaseVertex.edges() docstring now states which edges it returns for each graph kind (the old :return: said 'leaving' for both), that a self-loop is listed twice in an undirected graph, and that the result is a copy. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 17 |
| Duplication | 3 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #36 +/- ##
==========================================
+ Coverage 93.27% 93.36% +0.09%
==========================================
Files 3 3
Lines 1055 1055
==========================================
+ Hits 984 985 +1
+ Misses 71 70 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Oct 11, 2026
Owner
Author
|
Superseded by #43 ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
vertex.edges()andgraph.edges()returned the object's own edge list/set, so a caller could corrupt the graph without meaning to:and removing edges while iterating
v.edges()skipped some, becauseremove_edgemutates the list being iterated. Both now return a new container (list/set), so a caller can do what it likes with the result.Audit first
Nothing relied on the aliasing:
vertex.edges()isdegree(len()only);PoseGraph,LatticePlanner), MVTB and spatialmath only iterates the result or takes its length; none mutates it.Cost
graph.edges()on a 3,000-edge graph is about 9 µs per call;vertex.edges()is about 0.05 µs.Docs
The
BaseVertex.edges():return:said "edges leaving this vertex" for both graph kinds, which is wrong for an undirected graph (it lists incident edges). The docstring now states which edges are returned for each kind, that an undirected self-loop is listed twice (once per end, the same reason it counts 2 towards the degree), and that the result is a copy.Tests
tests/test_edges_copy.py, 24 tests acrossUGraphandDGraph(16 fail onmain): type, not the internal object, new object per call, clearing/appending to the result leaves the graph intact, removing while iterating is safe, contents and self-loop listing per graph kind. Full suite 239 passing, mypy and pyflakes clean.🤖 Generated with Claude Code