Skip to content

feat: add_edge() accepts an Edge as well as two vertices - #27

Merged
petercorke merged 3 commits into
mainfrom
feat/add-edge-accepts-edge
Oct 11, 2026
Merged

petercorke merged 3 commits into
mainfrom
feat/add-edge-accepts-edge

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

graph.add_edge() now accepts an Edge that already carries both vertices, mirroring add_vertex(), which takes coordinates or an existing vertex.

class MyEdge(Edge): ...
g.add_edge(MyEdge(v1, v2, data="a road"))   # was: TypeError, missing v2

The existing add_edge(v1, v2, **kwargs) forms are unchanged, so this is purely additive.

Behavior

  • add_edge(e) requires e.v1 and e.v2; otherwise ValueError, with a message pointing at add_edge(v1, v2, edge=e) / e.connect(v1, v2).
  • add_edge(e, v2) is a TypeError.
  • add_edge(e, cost=...) / data=... is a TypeError: connect() would silently ignore them when given an edge.
  • Typed with @overload.

One behavior tightening

add_edge() (both forms) now raises ValueError if the vertices belong to a different graph. Previously g.add_edge(x, y) with x, y from graph h silently added the edge to h.

Tests

tests/test_add_edge_edge.py, 21 tests across UGraph and DGraph. mypy: no new errors.

🤖 Generated with Claude Code

petercorke and others added 2 commits October 11, 2026 10:53
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
g.add_edge(MyEdge(v1, v2)) now works, mirroring add_vertex() which takes
coordinates or an existing vertex. The edge must already carry both
vertices; extra cost/data arguments are rejected since connect() would
silently ignore them. add_edge() (either form) now also refuses vertices
that belong to a different graph instead of silently adding the edge to
that graph.

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

codacy-production Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 20 complexity · 1 duplication

Metric Results
Complexity 20
Duplication 1

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.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.59%. Comparing base (cf7e537) to head (2bb12c0).

Files with missing lines Patch % Lines
src/pgraph/PGraph.py 90.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #27      +/-   ##
==========================================
+ Coverage   87.37%   87.59%   +0.21%     
==========================================
  Files           2        2              
  Lines         800      814      +14     
==========================================
+ Hits          699      713      +14     
  Misses        101      101              

☔ 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 b6e799a into main Oct 11, 2026
12 checks passed
@petercorke
petercorke deleted the feat/add-edge-accepts-edge branch October 11, 2026 04:04
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