-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correct annotation of headers parameter of HTTP event handlers (#5854)
* Use HTTPMessage for the headers parameter of HTTP event handlers While the documentation of `BaseHandler.http_error_default()` describes the `hdrs` (`headers` in most other handlers) as "a mapping object with the headers of the error", the implementation that is located in `URLopener._open_generic_http()` will pass `response.msg` instead, which is of type `http.client.HTTPMessage`. * Use Message for the headers parameter of HTTPError When the standard library constructs `HTTPError`, it will pass an `http.client.HTTPMessage`, which is a subclass of `email.message.Message`. Picking the superclass for the annotations gives users the flexibility to for example the result of the `email.message_from_X()` functions. The only thing unique to `HTTPMessage` is the undocumented `getallmatchingheaders()` method, which is only called by `http.server.CGIHTTPRequestHandler.run_cgi()`. That class gets its headers from `http.client.parse_headers()` and not from `HTTPError`, so I think it's safe to use `Message` as the annotation.
- Loading branch information
Showing
2 changed files
with
24 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters