Skip to content

refactor: graph.edges() returns a list in order of addition; both edges() return copies - #43

Merged
petercorke merged 1 commit into
mainfrom
refactor/edges-ordered-list
Oct 11, 2026
Merged

petercorke merged 1 commit into
mainfrom
refactor/edges-ordered-list

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

graph.edges() returns a list in order of addition, and both graph.edges() and vertex.edges() return copies. This supersedes #36, which made only the copy half of this change.

What was wrong

BaseGraph.edges() returned the graph's own set of edges, although it was documented as a list (0.6.5 :rtype: list of Edge references). So it had no defined order, and, like BaseVertex.edges(), it handed out the live container: clearing the result emptied the graph's records without updating ne, and removing edges while iterating over vertex.edges() skipped some.

Change

  • The graph keeps its edges in a dict[Edge, None] used as an insertion-ordered set (keyed by the edge object, hashed by identity). Removal is still O(1), and the attribute is renamed _edges so it no longer shares a name with the vertex's list.
  • graph.edges() is list(self._edges), vertex.edges() is list(self._edgelist); both are new lists.
  • Docstrings say which edges are returned for each vertex kind, that an undirected self-loop is listed twice at its vertex (once per end, as for the degree) but once in graph.edges(), and carry a versionchanged note.
  • Corrected two stale sentences found on the way: incidence() numbered edges "in the order they appear in graph.edges()" (now well defined) and claimed degree counts outgoing edges only (false since the degree change).

Breaking change (1.0)

graph.edges() is a list, not a set: code that used set operations on the result (|, -, .add()) needs set(g.edges()). Downstream, RTB's PoseGraph and LatticePlanner only iterate it.

Tests

tests/test_edges_list.py (22 tests, both graph kinds): type, order, order surviving removal, both results are copies, removing while iterating on both methods visits every edge, parallel edges, loops, Edge.remove, remove_vertex.

🤖 Generated with Claude Code

… edges() methods return copies

BaseGraph.edges() returned the graph's own set of edges (documented as a
list), so it had no order, and it, like BaseVertex.edges(), handed out the
live container: clearing the result emptied the graph's records without
updating ne, and removing edges while iterating skipped some.

The graph now keeps its edges in a dict used as an insertion-ordered set
(keyed by the edge object, hashed by identity), so removal is still O(1),
and both edges() methods return a new list.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 16 complexity · 0 duplication

Metric Results
Complexity 16
Duplication 0

View in Codacy

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

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.61%. Comparing base (eb78442) to head (a063fb2).

Files with missing lines Patch % Lines
src/pgraph/PGraph.py 90.90% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #43   +/-   ##
=======================================
  Coverage   94.61%   94.61%           
=======================================
  Files           3        3           
  Lines        1208     1208           
=======================================
  Hits         1143     1143           
  Misses         65       65           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@petercorke
petercorke merged commit b63389f into main Oct 11, 2026
13 of 14 checks passed
@petercorke
petercorke deleted the refactor/edges-ordered-list branch October 11, 2026 23:37
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.

1 participant