python / python/cpython

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

オープン
#123,503 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib type-feature
主要言語
Python
スター
77.2k
フォーク
36k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

issue でリンクされている HTTPErrorProcessor の実装について、Lib/urllib/request.py を読み、response.code と response.info() の使用に注目してください。開始する前にリンクされている PRs を確認し、そのうえで、生成される response オブジェクトがこれらの非推奨メンバーをもはや必要としないことを確認しつつ、ハンドラーの動作を維持してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
networking
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。