python / python/cpython

`HTTPErrorProcessor` uses deprecated members of `addinfourl`/`HTTPResponse`

Offen
#123,503 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

stdlib type-feature
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

https://github.com/python/cpython/blob/0181aa2e3efedc6504b27f6fe74f096e5e454286/Lib/urllib/request.py#L625

Per the docs for urllib.response.addinfourl and http.client.HTTPResponse, response.code and response.info() are deprecated as of Python 3.9. This is an issue when writing handlers that generate their own response objects—these objects must continue to provide the deprecated members.

I admit I don’t know how common or advisable this use case is, but it happened to me while I was implementing HTTP caching. When serving a response from the cache, I didn’t have a “real” response object to modify, and I wasn’t confident that I could instantiate the right thing from the standard library (the docs call it “a http.client.HTTPResponse object slightly modified”).

Instead, I made my own class that implemented just enough of the interface to get by. I thought that headers, status, url, and I/O read operations would suffice… but then I realised that HTTPErrorProcessor runs after all other handlers (including mine). So I would also need to add the deprecated members in order to be compatible.

See also #86203, where (if I’m reading correctly) it’s request objects that need to continue to provide deprecated members in order to work with the standard library.

Linked PRs
  • gh-123509
  • gh-123541
  • gh-132644
  • gh-132670

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Lies Lib/urllib/request.py bei der in der Issue verlinkten HTTPErrorProcessor-Implementierung und konzentriere dich dabei auf die Verwendung von response.code und response.info(). Prüfe die verlinkten PRs, bevor du beginnst, und bestätige anschließend, dass generierte Response-Objekte diese veralteten Member nicht mehr benötigen, während das Verhalten des Handlers erhalten bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
networking
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.