Skip to content

fix: connect(edge=) sets and validates the supplied edge's endpoints - #30

Merged
petercorke merged 4 commits into
mainfrom
fix/connect-edge-endpoints
Oct 11, 2026
Merged

petercorke merged 4 commits into
mainfrom
fix/connect-edge-endpoints

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

v1.connect(v2, edge=e) with a caller-supplied edge built without vertices added the edge to the graph but left e.v1 and e.v2 as None. The edge was then corrupt: incidence() and remove_edge() hit their assert ... is not None.

e = Edge(cost=7)
a.connect(b, edge=e)
e.v1, e.v2        # (None, None) before; (a, b) now

Edge.connect() set the endpoints, but BaseVertex.connect(edge=...) did not, and it also never checked an edge that already named other vertices.

Change

  • An edge with no vertices gets v1/v2 set to the vertices being connected.
  • An edge that already names different vertices is rejected with ValueError before anything is changed (no half-added edge).
  • A UGraph edge may be given in either order, since it has no direction. A DGraph edge must run exactly self -> dest.
  • Docstrings for BaseVertex.connect, UVertex.connect, DVertex.connect and Edge.connect now state the endpoint rule and :raises:. Edge.connect gains a warning that it is meant for an edge not yet in a graph.

Notes

  • Valid calls are unaffected: Edge(a, b) passed to a.connect(b, edge=...), and Edge.connect(v1, v2).
  • The tightening is the mismatched-endpoints case, which previously corrupted silently.
  • This is the base of a small stack: the vertex_class / edge_class PR builds on it, so it is worth merging first.

Tests

tests/test_connect_edge.py, 14 tests across UGraph and DGraph; nine fail on main.

🤖 Generated with Claude Code

petercorke and others added 4 commits October 11, 2026 10:52
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
v.connect(w, edge=Edge()) added an edge built without vertices to the
graph but left edge.v1/edge.v2 as None, so incidence() and remove_edge()
then hit their asserts. The endpoints are now set, and an edge that already
names other vertices is rejected before anything is changed (either order
is accepted for undirected edges).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…raph

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 21 complexity · 0 duplication

Metric Results
Complexity 21
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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.14%. Comparing base (173f548) to head (06b3ab4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #30      +/-   ##
==========================================
+ Coverage   85.05%   86.14%   +1.09%     
==========================================
  Files           2        2              
  Lines         776      787      +11     
==========================================
+ Hits          660      678      +18     
+ Misses        116      109       -7     

☔ 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 e368024 into main Oct 11, 2026
14 checks passed
@petercorke
petercorke deleted the fix/connect-edge-endpoints branch October 11, 2026 03:57
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