Thanks to visit codestin.com
Credit goes to github.com

Skip to content

urllib.request.HTTPRedirectHandler documentation uses hdrs instead of headers #135468

Open
@niooss-ledger

Description

@niooss-ledger

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions