-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Description
Line 625 in 0181aa2
| code, msg, hdrs = response.code, response.msg, response.info() |
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-123503: Replace deprecated members from
urllib/request#123509 - gh-123503: Replace deprecated members from
urllib/request#123541 - gh-123503: Replace usages of
addinfourlandHTTPResponsedeprecated attributes with stable ones #132644 - gh-123503: Replace usages of addinfourl and HTTPResponse deprecated attributes with stable ones #132670