Skip to content

Response repr dumps the entire body; add a concise __repr__ #43

Closed

Description

@owenthcarey

Problem

Response in src/pythonnative/net.py (lines 59-104) is a dataclass with a content: bytes field, so the auto-generated repr prints the full response body and all headers. Logging or debugging a fetch call against any real endpoint floods the console:

resp = await pn.fetch("https://example.com/big.json")
print(resp)  # Response(status=200, url='...', headers={...}, content=b'<many KB of bytes>')

Suggested fix

Add a custom __repr__ that summarizes the body instead of dumping it, for example:

def __repr__(self) -> str:
    return f"Response(status={self.status}, url={self.url!r}, ok={self.ok}, content={len(self.content)} bytes)"

Alternatively, mark the field with field(repr=False) and add the length some other way; a custom __repr__ reads better.

Verification

  • Add a small unit test to tests/test_net.py asserting the repr contains the status and byte count but not the body. The existing echo-server fixture in that file makes this easy.
  • ./scripts/check.sh passes.

Suggested commit message

feat(net): add concise __repr__ to Response

Activity

  1. added
    enhancement
    good first issue
    on Sep 1, 2026
  2. glenlouis8 commented on Sep 1, 2026

    @glenlouis8
    Contributor

    I'd like to take this one. Plan: add a custom repr to Response in src/pythonnative/net.py that summarizes the body as a byte count instead of dumping it, and add a test in tests/test_net.py asserting the repr shows status and byte count but not the body.

  3. owenthcarey commented on Sep 1, 2026

    @owenthcarey
    ContributorAuthor

    Thank you! Assigned to you.

  4. glenlouis8 commented on Sep 1, 2026

    @glenlouis8
    Contributor

    Opened #49 for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementgood first issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions