Skip to content

refactor: vertex kinds supply _detach, the twin of _attach; removed vertices leave the graph - #38

Merged
petercorke merged 2 commits into
mainfrom
refactor/detach-hook
Oct 11, 2026
Merged

petercorke merged 2 commits into
mainfrom
refactor/detach-hook

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

remove_edge knew how each vertex kind held an edge: a per-endpoint "is it in this list?" check written for the directed case. That is now the vertex kind's job, as _attach already is for connect:

  • UVertex._detach removes the edge from both ends (twice for a self-loop); DVertex._detach from the source.
  • remove_edge calls it once, before clearing the edge's endpoints. Behaviour is unchanged.

Also fixes remove_vertex leaving vertex._graph pointing at the graph it had been removed from. That made a later connect() report "different graphs" rather than "not in a graph", and made vertex.remove() fail confusingly.

Tests

tests/test_detach_hook.py: _detach is the exact inverse of _attach for both kinds (including loops and parallel edges), and a removed vertex leaves its graph.

🤖 Generated with Claude Code

petercorke and others added 2 commits October 12, 2026 09:16
… graph

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ertices leave the graph

remove_edge knew how each vertex kind held an edge (a per-endpoint
'is it in this list?' check written for the directed case). That is now the
vertex kind's job: UVertex._detach removes the edge from both ends (twice for
a self-loop) and DVertex._detach from the source. remove_edge calls it once,
before clearing the edge's endpoints. Behaviour is unchanged.

Also fixes remove_vertex leaving vertex._graph pointing at the graph it had
been removed from, which made a later connect() report 'different graphs'
rather than 'not in a graph', and made vertex.remove() fail confusingly.

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 33 complexity · 4 duplication

Metric Results
Complexity 33
Duplication 4

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.

@petercorke
petercorke merged commit f3e1e04 into main Oct 11, 2026
12 checks passed
@petercorke
petercorke deleted the refactor/detach-hook branch October 11, 2026 23:19
@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.79%. Comparing base (36fdbc8) to head (74a87c7).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/pgraph/PGraph.py 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #38      +/-   ##
==========================================
+ Coverage   93.63%   93.79%   +0.15%     
==========================================
  Files           3        3              
  Lines        1053     1063      +10     
==========================================
+ Hits          986      997      +11     
+ Misses         67       66       -1     

☔ 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.

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