Repository navigation
refactor: connect() defined once, vertex kinds supply an _attach hook - #35
Merged
Merged
Conversation
…hook Fails on main: UVertex/DVertex override connect() and there is no _attach. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…tach hook UVertex.connect and DVertex.connect were the same sequence -- super().connect(), then append the edge to one or two edge lists -- differing only in that last line, and each repeated the full signature and docstring. A new vertex kind had to know to call super() first. BaseVertex.connect now validates, registers the edge with the graph and then calls self._attach(edge, dest). UVertex._attach records the edge at both ends, DVertex._attach at the source only, and BaseVertex._attach raises NotImplementedError. BaseVertex itself stays instantiable (policy.rst) and can still never join a graph, so the base hook is unreachable in practice. The public signature and behaviour are unchanged. The per-kind description and example move from the removed overrides to the UVertex/DVertex class docstrings and one note on BaseVertex.connect. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 21 |
| 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 #35 +/- ##
==========================================
+ Coverage 93.27% 93.54% +0.27%
==========================================
Files 3 3
Lines 1055 1054 -1
==========================================
+ Hits 984 986 +2
+ Misses 71 68 -3 ☔ 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
UVertex.connect()andDVertex.connect()were the same few lines (callsuper().connect(), then append the edge to one or two edge lists) differing only in that last line, and each repeated the full signature and docstring. A new vertex kind had to know to callsuper()first, and the edge rules had to be documented three times.connect()is now defined once, onBaseVertex, and the vertex kinds supply a single bookkeeping hook,_attach(Template Method):Why not make
connect()itself abstractBaseVertexis documented as constructible (policy.rst), and a bareBaseVertexcan never join a graph anyway (connect()raisesValueError,add_vertex()raisesTypeError), so abstractness would break the documented behavior and prevent nothing. The hook is what varies, so the hook is what a subclass supplies; the base one raisesNotImplementedError.Behavior
None. Signature, return value, exceptions and edge-list contents are unchanged,
add_edge()andEdge.connect()both still go throughconnect(), and the full existing suite passes untouched.Docs
The "unlike the directed counterpart" text and the per-kind example moved from the removed overrides to the
UVertex/DVertexclass docstrings, andBaseVertex.connectgains one note stating who holds the edge and the endpoint rule for each kind.Tests
tests/test_vertex_hook.py, 18 tests:connectis defined once (UVertex.connect is BaseVertex.connect), the hook is called exactly once and after the edge is registered, nothing is attached when validation refuses (wrong graph, wrong endpoints, ungraphed), self-loops are held twice by an undirected and once by a directed vertex, a bareBaseVertexis still constructible but cannot connect or be added, and a user vertex kind can change the bookkeeping by overriding only_attach. Suite: 233 passing, mypy clean.🤖 Generated with Claude Code