Repository navigation
feat: one Vertex class; Graph(directed=...) chooses the kind of graph - #47
Merged
Merged
Conversation
UVertex and DVertex differed only in four private methods that recorded an edge at its ends, which is the graph's decision, not the vertex's: a vertex has no direction of its own. Having the kind in both the graph and its vertices meant keeping them consistent, with checks (add_vertex's kind test, vertex_class's kind test) whose only job was to refuse the combinations the design allowed to be written. - the hooks _attach, _detach, _incoming and _endpoints_match move to the graph kinds: UGraph records an edge at both ends, DGraph as leaving its start and entering its end. Vertex.connect calls the graph's hook - there is one vertex class, Vertex. UVertex and DVertex remain as deprecated names for it (module __getattr__, DeprecationWarning), so existing code that subclasses or constructs them runs; they are not in __all__ - Graph is concrete: Graph(directed=True) is a DGraph and Graph() a UGraph, so the kind can be a variable; Graph.Adjacency and Graph.Dict take directed= the same way. UGraph(directed=True) is a ValueError. isinstance, the hooks and pickling see the honest subclass - Graph.directed reports the kind, replacing the isinstance tests in Adjacency, iscyclic, incidence, validate, the exporters and Edge.__str__ - vertex_class need only be a subclass of Vertex Behaviour change: add_vertex no longer has a wrong-kind vertex to refuse, and a bare Vertex, which could not join any graph, now can. An Edge between standalone vertices has no kind to show, so its str uses -- not ->. Tests: the hook tests exercise the graph hooks; test_unified_graph covers the dispatch, the aliases and the kind-aware constructors. Downstream, MVTB's bundle-adjust tests and RTB's mobile and planner tests pass through the aliases. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The examples, the policy page and the README use Vertex, the pages for UVertex and DVertex are removed, and the common page says that a vertex has no direction of its own. Only what the new API makes wrong or runnable-with-a-warning is changed; the full documentation and diagram pass follows. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 48 |
| Duplication | -2 |
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❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #47 +/- ##
==========================================
+ Coverage 94.79% 95.27% +0.48%
==========================================
Files 3 3
Lines 1249 1271 +22
==========================================
+ Hits 1184 1211 +27
+ Misses 65 60 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Graph(directed=...) returns a UGraph or DGraph, so it is no longer abstract: the abstractmethod made static checkers report that an abstract class was instantiated. _graphcolor in the base raises NotImplementedError like the other hooks, and a direct subclass that does not say its kind is a TypeError at construction. Also tests the module-level deprecated names and the base hooks, and removes an unused import. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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
There is one vertex class,
Vertex, andGraph(directed=...)chooses the kind of graph.UVertexandDVertexdiffered only in four private methods that recorded an edge at its ends, and that is the graph's decision, not the vertex's: a vertex has no direction of its own. Having the kind in both the graph and its vertices meant keeping them consistent, with checks (add_vertex's kind test,vertex_class's kind test) whose only job was to refuse the combinations the design allowed to be written._attach,_detach,_incomingand_endpoints_matchmove to the graph kinds:UGraphrecords an edge at both ends,DGraphas leaving its start and entering its end.Vertex.connectcalls the graph's hook.UVertexandDVertexremain as deprecated names forVertex(module__getattr__,DeprecationWarning), so existing code that subclasses or constructs them runs. They are not in__all__.Graphis concrete:Graph(directed=True)is aDGraphandGraph()aUGraph, so the kind can be a variable;Graph.AdjacencyandGraph.Dicttakedirected=the same way.UGraph(directed=True)is aValueError.isinstance, the hooks and pickling see the honest subclass.Graph.directedreports the kind, replacing theisinstancetests inAdjacency,iscyclic,incidence,validate, the exporters andEdge.__str__.vertex_classneed only be a subclass ofVertex.Behaviour changes (1.0)
Vertex, which could not join any graph, now can; there is no longer a wrong-kind vertex foradd_vertexto refuse.Edgebetween standalone vertices has no kind to show, so itsstruses--, not->.Vertexno longer has_attach/_detach; code overriding those on a vertex moves the override to aUGraph/DGraphsubclass (seetest_vertex_hook.py::TestHookIsTheExtensionPoint).Downstream
Checked against this branch with the deprecated aliases: MVTB's bundle-adjust tests (4) and RTB's mobile and planner tests (21) pass. RTB's
PoseGraph/LatticePlannerand MVTB'sViewPoint/Landmarkshould changeUVertex/DVertextoVertex; they get aDeprecationWarninguntil then.Tests
The hook tests exercise the graph hooks. New
tests/test_unified_graph.py(28 tests): the dispatch,directedand its contradictions, one vertex class serving both kinds, the deprecated names (warn, subclass, not advertised, not in__all__), the kind-aware constructors, copy and pickle keeping the kind, the edge arrow.Docs
Only what the new API makes wrong, or runnable with a warning, is changed (examples,
policy.rst, README, the two removed vertex pages). The full documentation and diagram pass follows.🤖 Generated with Claude Code