Skip to content

fix: repr(g) is the one-line summary, show() lists the vertices - #87

Merged
petercorke merged 1 commit into
mainfrom
fix/graph-repr
Oct 31, 2026
Merged

petercorke merged 1 commit into
mainfrom
fix/graph-repr

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Part of #23.

What

Graph had two __repr__ definitions. The first returned str(self) and was shadowed by the second, which printed one line per vertex. A type: ignore[no-redef] hid the redefinition.

A repr is what appears in a notebook cell, a debugger pane, a log line, pytest output and error messages, so a repr as long as the graph is a hazard on a large one.

  • One __repr__, the same one-line summary as __str__: UGraph: 3 vertices, 2 edges, 1 component.
  • show() now prints what the long repr did: each vertex with its name, coordinate and component number (edges are unchanged).
  • plot() and show() refer to each other in :seealso:, as do __str__, __repr__ and show().

Behaviour change

repr(g) changes from a listing to one line, and show() gains the coordinate and component on each vertex line. Both carry .. versionchanged:: 1.1. I found no use of the graph's repr in RTB's or MVTB's source. The CHANGELOG line is left until the Unreleased section exists (#78 is adding it).

Tests

  • the repr is the one-line summary, and stays one line for 500 vertices
  • show() output against hand-written lines, including a second component and an edge
  • show() on a vertex with no coordinate

pytest tests: 775 passed. mypy src: clean. The nitpicky docs build has the same 11 warnings with and without the change, none for these methods.

🤖 Generated with Claude Code

The graph had two __repr__ definitions in one class.  The first returned
str(self) and was shadowed by the second, which printed one line per vertex,
so a repr (a notebook cell, a debugger, a log line, an error message) was as
long as the graph.  A type: ignore[no-redef] hid the redefinition.

Keep one __repr__, the same one-line summary as __str__, and have show()
print what the long repr did: each vertex with its name, coordinate and
component number.  plot() and show() now refer to each other in :seealso:.

Part of #23.

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

Metric Results
Complexity 4
Duplication 0

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 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.98%. Comparing base (4e1c1f9) to head (548fb5f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #87      +/-   ##
==========================================
+ Coverage   97.54%   97.98%   +0.43%     
==========================================
  Files           4        4              
  Lines        1591     1586       -5     
==========================================
+ Hits         1552     1554       +2     
+ Misses         39       32       -7     

☔ 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 343a0f2 into main Oct 31, 2026
14 checks passed
@petercorke
petercorke deleted the fix/graph-repr branch October 31, 2026 03:32
@petercorke petercorke mentioned this pull request Oct 31, 2026
10 tasks
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