fill out stubs for requests.structures (#1897)

Looked at https://github.com/requests/requests/blob/master/requests/structures.py.

The "data" argument to the CaseInsensitiveDict constructor is passed as is to .update(),
so I accept the same argument types as MutableMapping.update.

LookupDict is strangely named and implemented but the point seems to be that you
setattr its keys, and then can access them with both attribute access and subscripting.
See its usage in d1fb1a29ab/requests/status_codes.py (L102).
This commit is contained in:
Jelle Zijlstra
2018-04-06 11:36:43 -07:00
committed by Guido van Rossum
parent 482f207b3c
commit 8482b1030b

View File

@@ -1,8 +1,9 @@
from typing import Any, Iterator, MutableMapping, Tuple, TypeVar, Generic
from typing import Any, Dict, Iterable, Iterator, Mapping, MutableMapping, Optional, Tuple, TypeVar, Union, Generic
_VT = TypeVar('_VT')
class CaseInsensitiveDict(MutableMapping[str, _VT], Generic[_VT]):
def __init__(self, data: Optional[Union[Mapping[str, _VT], Iterable[Tuple[str, _VT]]]] = ..., **kwargs: _VT) -> None: ...
def lower_items(self) -> Iterator[Tuple[str, _VT]]: ...
def __setitem__(self, key: str, value: _VT) -> None: ...
def __getitem__(self, key: str) -> _VT: ...
@@ -10,8 +11,9 @@ class CaseInsensitiveDict(MutableMapping[str, _VT], Generic[_VT]):
def __iter__(self) -> Iterator[str]: ...
def __len__(self) -> int: ...
class LookupDict(dict):
name = ... # type: Any
def __init__(self, name=...) -> None: ...
def __getitem__(self, key): ...
def get(self, key, default=...): ...
class LookupDict(Dict[str, _VT]):
name: Any
def __init__(self, name: Any = ...) -> None: ...
def __getitem__(self, key: str) -> Optional[_VT]: ... # type: ignore
def __getattr__(self, attr: str) -> _VT: ...
def __setattr__(self, attr: str, value: _VT) -> None: ...