Skip to content

feat(net): add concise __repr__ to Response - #49

Merged
owenthcarey merged 1 commit into
pythonnative:mainfrom
glenlouis8:feat/net-response-repr
Sep 2, 2026
Merged

owenthcarey merged 1 commit into
pythonnative:mainfrom
glenlouis8:feat/net-response-repr

Conversation

@glenlouis8

Copy link
Copy Markdown
Contributor

What

  • Add a custom Response.__repr__ that summarizes the body as a byte count.

Why

  • Response is a @dataclass with a content: bytes field, so the auto-generated repr dumps the entire response body. Logging or printing a fetch result against a real endpoint floods the console with raw bytes.

How (brief)

  • src/pythonnative/net.py: define Response.__repr__ returning Response(status=..., url=..., ok=..., content=<n> bytes). Uses type(self).__name__ so a subclass reprs with its own name.
  • tests/test_net.py: add test_repr_summarizes_body (uses the existing echo-server fixture) asserting the repr contains the status and byte count but not the decoded body.

Testing

  • ./scripts/check.sh passes.

Risks/Impact

  • Changes the repr string only. No effect on status, url, headers, content, or any method. Response is not equality-compared anywhere (dataclass eq still auto-generated).

Docs/Follow-ups

  • None.

Closes #43

@owenthcarey
owenthcarey merged commit 2ffc701 into pythonnative:main Sep 2, 2026
15 checks passed
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.

Response repr dumps the entire body; add a concise __repr__

2 participants