From 8482b1030bf8bb03c9c9d830d87bb9c4455353a4 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 6 Apr 2018 11:36:43 -0700 Subject: [PATCH] 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 https://github.com/requests/requests/blob/d1fb1a29ab949223d8d64797e0fcc9a7d2690483/requests/status_codes.py#L102. --- third_party/2and3/requests/structures.pyi | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/third_party/2and3/requests/structures.pyi b/third_party/2and3/requests/structures.pyi index 9956e9c5a..92cf27aa1 100644 --- a/third_party/2and3/requests/structures.pyi +++ b/third_party/2and3/requests/structures.pyi @@ -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: ...