Skip to content

Commit

Permalink
Support fuller files kwarg for requests.post
Browse files Browse the repository at this point in the history
The files keyword argument for the requests.post function has this type:

files: _Files | None = ...

This commit adds this type alias as found in requests version 2.32.2 and
updates this library's multipart_matcher function's files keyword
argument to be of type _Files.
  • Loading branch information
semperos committed Dec 12, 2024
1 parent 7a6348a commit 80a5d2e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion responses/matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from json.decoder import JSONDecodeError
from typing import Any
from typing import Callable
from typing import Iterable
from typing import List
from typing import Mapping
from typing import MutableMapping
Expand Down Expand Up @@ -275,8 +276,19 @@ def match(request: PreparedRequest) -> Tuple[bool, str]:
return match


_FileName = Optional[str]
_FileContent = Union[str, bytes]
_FileContentType = str
_FileCustomHeaders = Mapping[str, str]
_FileSpecTuple2 = tuple[_FileName, _FileContent]
_FileSpecTuple3 = tuple[_FileName, _FileContent, _FileContentType]
_FileSpecTuple4 = tuple[_FileName, _FileContent, _FileContentType, _FileCustomHeaders]
_FileSpec = Union[_FileContent, _FileSpecTuple2, _FileSpecTuple3, _FileSpecTuple4]
_Files = Union[Mapping[str, _FileSpec], Iterable[tuple[str, _FileSpec]]]


def multipart_matcher(
files: Mapping[str, Any], data: Optional[Mapping[str, str]] = None
files: _Files, data: Optional[Mapping[str, str]] = None
) -> Callable[..., Any]:
"""
Matcher to match 'multipart/form-data' content-type.
Expand Down

0 comments on commit 80a5d2e

Please sign in to comment.