Documentation
Hello, HTTPRedirectHandler documentation documents some methods take HTTP headers in a parameter named hdrs:
|
.. method:: HTTPRedirectHandler.redirect_request(req, fp, code, msg, hdrs, newurl) |
|
.. method:: HTTPRedirectHandler.http_error_301(req, fp, code, msg, hdrs) |
|
.. method:: HTTPRedirectHandler.http_error_302(req, fp, code, msg, hdrs) |
...
However, the actual implementation uses headers:
|
def redirect_request(self, req, fp, code, msg, headers, newurl): |
|
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:
pass
Running 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
Documentation
Hello,
HTTPRedirectHandlerdocumentation documents some methods take HTTP headers in a parameter namedhdrs:cpython/Doc/library/urllib.request.rst
Line 896 in c646846
cpython/Doc/library/urllib.request.rst
Line 915 in c646846
cpython/Doc/library/urllib.request.rst
Line 921 in c646846
...
However, the actual implementation uses
headers:cpython/Lib/urllib/request.py
Line 621 in c646846
cpython/Lib/urllib/request.py
Line 660 in c646846
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:
Running a type checker (basedpyright) on this code reports a warning:
This was quite unexpected because the official documentation (https://docs.python.org/3.13/library/urllib.request.html#urllib.request.HTTPRedirectHandler.redirect_request) mentions
hdrsinstead ofheaders. It makes nonetheless more sense to name the parameterheadersin case callers use the parameter names.Linked PRs
BaseHandler.http_error_default()parameter descriptions #136797BaseHandler.http_error_default()parameter descriptions (GH-136797) #136825BaseHandler.http_error_default()parameter descriptions (GH-136797) #136826