python / python/cpython

http.client.HTTPConnection and HTTPResponse are missing __repr__

Open
#145,651 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

http.client.HTTPConnection and HTTPResponse lack repr implementations, producing the default unhelpful object repr:

>>> import http.client
>>> http.client.HTTPConnection('example.com')
<http.client.HTTPConnection object at 0x...>

These should show useful state at a glance:

>>> http.client.HTTPConnection('example.com')
<HTTPConnection example.com:80>
>>> http.client.HTTPSConnection('example.com')
<HTTPSConnection example.com:443>

And for responses:

>>> r = conn.getresponse()
>>> r
<HTTPResponse [200 OK]>

The module already has a repr on IncompleteRead, so there's precedent. This would help when debugging HTTP code in the REPL or debugger.

Linked PRs
  • gh-145653

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the http.client module and inspect the existing IncompleteRead repr for precedent. Add useful representations for HTTPConnection, HTTPSConnection, and HTTPResponse matching the examples, then verify the connection and response output in relevant tests; linked PR gh-145653 indicates the work is already underway.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.