Repository navigation
feat: UGraph/DGraph take vertex_class and edge_class - #31
Merged
Merged
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A graph now owns the policy of which vertex and edge classes it builds, so
user subclasses no longer have to be constructed by hand and passed in:
g = UGraph(vertex_class=MyVertex, edge_class=MyEdge)
g.add_vertex([0, 0]) # MyVertex
g.add_edge(v1, v2) # MyEdge
add_vertex() and connect(edge=) enforce the configured classes; the
Dict() and Adjacency() factories forward constructor arguments; copy()
preserves them. Defaults are unchanged (UVertex/DVertex and Edge).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…, DGraph, factories Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 35 |
| Duplication | 0 |
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 #31 +/- ##
==========================================
+ Coverage 89.37% 90.31% +0.94%
==========================================
Files 2 2
Lines 828 847 +19
==========================================
+ Hits 740 765 +25
+ Misses 88 82 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
A graph now owns the policy of which vertex and edge classes it builds, so user subclasses never have to be constructed by hand and passed in:
Defaults are unchanged (
UVertex/DVertexandEdge), so existing code is unaffected.Behavior
vertex_classmust subclass the graph's own vertex kind (UVertexforUGraph,DVertexforDGraph);edge_classmust subclassEdge. Otherwise the constructor raisesTypeError.add_vertex(v)only accepts instances of the graph'svertex_class;connect(edge=e)only accepts instances of itsedge_class(TypeErrorotherwise). For a default graph this still admits anyUVertex/DVertex/Edgesubclass.g.vertex_class/g.edge_class; preserved bycopy().UGraph.Dict()andUGraph.Adjacency()forward extra keyword arguments to the constructor.vertex_class(coord, name=name)andedge_class(v1, v2, cost=cost, data=data); this contract is in the constructor docstring.For review
The strictness is the part most worth a second look: a graph configured with
vertex_class=MyVertexrejects a plainUVertex. That is the point of configuring it (the type ofg[i]can be relied on), but it is a choice.Docstrings for
UGraph,DGraph,Edge,connect()and the factories are updated, including the exceptions.Tests
tests/test_graph_classes.py, 28 tests acrossUGraphandDGraph. mypy: no new errors.🤖 Generated with Claude Code