mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 04:54:47 +08:00
* 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.