Skip to content

Incorrect Requests Typing #7720

Closed
Closed

Description

@AlecRosenbaum

A lot of new typing for requests was introduced with #7696. This is great! Except there's a minor bug that doesn't line up with requests actual accepted types.

The first element of the tuples for _Files should be Optional[str]:

_Files: TypeAlias = (
MutableMapping[str, IO[Any]]
| MutableMapping[str, tuple[str, IO[Any]]]
| MutableMapping[str, tuple[str, IO[Any], str]]
| MutableMapping[str, tuple[str, IO[Any], str, _TextMapping]]
)

The files arg is passed through a bunch of layers within requests and eventually actually handled here:
https://github.com/psf/requests/blob/fa1b0a367abc8488542f7ce7c02a3614ad8aa09d/requests/models.py#L143-L169

The first arg of a tuple becomes the filename passed to urllib3.fields.RequestField, which is typed as optional:
https://github.com/urllib3/urllib3/blob/e16beb210c03c6f5ce4e0908bddb6556442b6a37/src/urllib3/fields.py#L178-L185

Activity

  1. Akuli commented on Apr 27, 2022

    @Akuli
    Collaborator

    PR welcome!

  2. added a commit that references this issue on Apr 27, 2022
    63fb9af
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions