Allow requests.post to accept Dict[str, str] for data. (#1777)

* Allow `requests.post` to accept `Dict[str, str]` for `data`.

For example:

```python
import requests
requests.post('https://www.foo.bar', data={'hello': 'world'})
```

Failes to type check in Python 2 even though it's fine.

* Explode str/Text combinations

* Fix lint

* Simplify iterable parameter for data
This commit is contained in:
Roy Williams
2017-12-14 20:36:21 -08:00
committed by Jelle Zijlstra
parent 398401baee
commit 1dccd1fdc4

View File

@@ -1,26 +1,41 @@
# Stubs for requests.api (Python 3)
import sys
from typing import Optional, Union, Any, Iterable, Mapping, MutableMapping, Tuple, IO, Text
from .models import Response
_ParamsMappingValueType = Union[Text, bytes, int, float, Iterable[Union[Text, bytes, int, float]]]
_Data = Union[None, bytes, MutableMapping[Text, Text], Iterable[Tuple[Text, Text]], IO]
if sys.version_info >= (3,):
_Text = str
else:
_Text = Union[str, Text]
_ParamsMappingValueType = Union[_Text, bytes, int, float, Iterable[Union[_Text, bytes, int, float]]]
_Data = Union[
None,
bytes,
MutableMapping[str, str],
MutableMapping[str, Text],
MutableMapping[Text, str],
MutableMapping[Text, Text],
Iterable[Tuple[_Text, _Text]],
IO
]
def request(method: str, url: str, **kwargs) -> Response: ...
def get(url: Union[Text, bytes],
def get(url: Union[_Text, bytes],
params: Optional[
Union[Mapping[Union[Text, bytes, int, float], _ParamsMappingValueType],
Union[Text, bytes],
Tuple[Union[Text, bytes, int, float], _ParamsMappingValueType],
Mapping[Text, _ParamsMappingValueType],
Union[Mapping[Union[_Text, bytes, int, float], _ParamsMappingValueType],
Union[_Text, bytes],
Tuple[Union[_Text, bytes, int, float], _ParamsMappingValueType],
Mapping[_Text, _ParamsMappingValueType],
Mapping[bytes, _ParamsMappingValueType],
Mapping[int, _ParamsMappingValueType],
Mapping[float, _ParamsMappingValueType]]] = ...,
**kwargs) -> Response: ...
def options(url: Union[str, Text], **kwargs) -> Response: ...
def head(url: Union[str, Text], **kwargs) -> Response: ...
def post(url: Union[str, Text], data: _Data=..., json=..., **kwargs) -> Response: ...
def put(url: Union[str, Text], data: _Data=..., json=..., **kwargs) -> Response: ...
def patch(url: Union[str, Text], data: _Data=..., json=..., **kwargs) -> Response: ...
def delete(url: Union[str, Text], **kwargs) -> Response: ...
def options(url: _Text, **kwargs) -> Response: ...
def head(url: _Text, **kwargs) -> Response: ...
def post(url: _Text, data: _Data=..., json=..., **kwargs) -> Response: ...
def put(url: _Text, data: _Data=..., json=..., **kwargs) -> Response: ...
def patch(url: _Text, data: _Data=..., json=..., **kwargs) -> Response: ...
def delete(url: _Text, **kwargs) -> Response: ...