-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
Description
Documentation
Hello, HTTPRedirectHandler documentation documents some methods take HTTP headers in a parameter named hdrs:
cpython/Doc/library/urllib.request.rst
Line 896 in c646846
| .. method:: HTTPRedirectHandler.redirect_request(req, fp, code, msg, hdrs, newurl) |
cpython/Doc/library/urllib.request.rst
Line 915 in c646846
| .. method:: HTTPRedirectHandler.http_error_301(req, fp, code, msg, hdrs) |
cpython/Doc/library/urllib.request.rst
Line 921 in c646846
| .. method:: HTTPRedirectHandler.http_error_302(req, fp, code, msg, hdrs) |
...
However, the actual implementation uses headers:
Line 621 in c646846
| def redirect_request(self, req, fp, code, msg, headers, newurl): |
Line 660 in c646846
| def http_error_302(self, req, fp, code, msg, headers): |
Would it be possible to use the same name in the documentation and in the implementation?
Context
In some project, the following class is used to perform HTTPS requests without following redirection:
class NoRedirect(urllib.request.HTTPRedirectHandler):
def redirect_request(
self, req: Any, fp: Any, code: Any, msg: Any, hdrs: Any, newurl: Any
) -> None:
passRunning a type checker (basedpyright) on this code reports a warning:
error: Method "redirect_request" overrides class "HTTPRedirectHandler" in an incompatible manner
Parameter 6 name mismatch: base parameter is named "headers",
override parameter is named "hdrs" (reportIncompatibleMethodOverride)
This was quite unexpected because the official documentation (https://docs.python.org/3.13/library/urllib.request.html#urllib.request.HTTPRedirectHandler.redirect_request) mentions hdrs instead of headers. It makes nonetheless more sense to name the parameter headers in case callers use the parameter names.
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status
Status