Skip to content

Incorrect Requests Typing #7720

@AlecRosenbaum

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions