From b915d0d7b447b83f640850c3c8e2447a3b194f31 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Mon, 24 Jan 2022 16:55:10 +0200 Subject: [PATCH] Revert #644, restore type annotations to as-of 5.2.0 version --- multidict/__init__.pyi | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/multidict/__init__.pyi b/multidict/__init__.pyi index 47a03bf37..24ba63054 100644 --- a/multidict/__init__.pyi +++ b/multidict/__init__.pyi @@ -17,7 +17,7 @@ class istr(str): ... upstr = istr -_S = TypeVar("_S", str, istr) +_S = Union[str, istr] _T = TypeVar("_T") @@ -39,17 +39,13 @@ class MultiMapping(Mapping[_S, _T_co]): @abc.abstractmethod def getone(self, key: _S, default: _D) -> Union[_T_co, _D]: ... -_Arg = Union[ - Mapping[_S, _T], Dict[_S, _T], MultiMapping[_S, _T], Iterable[Tuple[_S, _T]] -] +_Arg = Union[Mapping[_S, _T], Dict[_S, _T], MultiMapping[_T], Iterable[Tuple[_S, _T]]] -class MutableMultiMapping( - MultiMapping[_S, _T], MutableMapping[_S, _T], Generic[_S, _T] -): +class MutableMultiMapping(MultiMapping[_T], MutableMapping[_S, _T], Generic[_T]): @abc.abstractmethod def add(self, key: _S, value: _T) -> None: ... @abc.abstractmethod - def extend(self, arg: _Arg[_S, _T] = ..., **kwargs: _T) -> None: ... + def extend(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ... @overload @abc.abstractmethod def popone(self, key: _S) -> _T: ... @@ -63,8 +59,8 @@ class MutableMultiMapping( @abc.abstractmethod def popall(self, key: _S, default: _D) -> Union[List[_T], _D]: ... -class MultiDict(MutableMultiMapping[str, _T]): - def __init__(self, arg: _Arg[_S, _T] = ..., **kwargs: _T) -> None: ... +class MultiDict(MutableMultiMapping[_T], Generic[_T]): + def __init__(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ... def copy(self) -> MultiDict[_T]: ... def __getitem__(self, k: _S) -> _T: ... def __setitem__(self, k: _S, v: _T) -> None: ... @@ -80,7 +76,7 @@ class MultiDict(MutableMultiMapping[str, _T]): @overload def getone(self, key: _S, default: _D) -> Union[_T, _D]: ... def add(self, key: _S, value: _T) -> None: ... - def extend(self, arg: _Arg[_S, _T] = ..., **kwargs: _T) -> None: ... + def extend(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ... @overload def popone(self, key: _S) -> _T: ... @overload @@ -90,8 +86,8 @@ class MultiDict(MutableMultiMapping[str, _T]): @overload def popall(self, key: _S, default: _D) -> Union[List[_T], _D]: ... -class CIMultiDict(MutableMultiMapping[istr, _T]): - def __init__(self, arg: _Arg[_S, _T] = ..., **kwargs: _T) -> None: ... +class CIMultiDict(MutableMultiMapping[_T], Generic[_T]): + def __init__(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ... def copy(self) -> CIMultiDict[_T]: ... def __getitem__(self, k: _S) -> _T: ... def __setitem__(self, k: _S, v: _T) -> None: ... @@ -107,7 +103,7 @@ class CIMultiDict(MutableMultiMapping[istr, _T]): @overload def getone(self, key: _S, default: _D) -> Union[_T, _D]: ... def add(self, key: _S, value: _T) -> None: ... - def extend(self, arg: _Arg[_S, _T] = ..., **kwargs: _T) -> None: ... + def extend(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ... @overload def popone(self, key: _S) -> _T: ... @overload @@ -117,9 +113,9 @@ class CIMultiDict(MutableMultiMapping[istr, _T]): @overload def popall(self, key: _S, default: _D) -> Union[List[_T], _D]: ... -class MultiDictProxy(MultiMapping[str, _T]): +class MultiDictProxy(MultiMapping[_T], Generic[_T]): def __init__( - self, arg: Union[MultiDict[_T], MultiDictProxy[_T]] + self, arg: Union[MultiMapping[_T], MutableMultiMapping[_T]] ) -> None: ... def copy(self) -> MultiDict[_T]: ... def __getitem__(self, k: _S) -> _T: ... @@ -134,11 +130,10 @@ class MultiDictProxy(MultiMapping[str, _T]): @overload def getone(self, key: _S, default: _D) -> Union[_T, _D]: ... -class CIMultiDictProxy(MultiMapping[istr, _T]): +class CIMultiDictProxy(MultiMapping[_T], Generic[_T]): def __init__( - self, arg: Union[CIMultiDict[_T], CIMultiDictProxy[_T]] + self, arg: Union[MultiMapping[_T], MutableMultiMapping[_T]] ) -> None: ... - def copy(self) -> CIMultiDict[_T]: ... def __getitem__(self, k: _S) -> _T: ... def __iter__(self) -> Iterator[_S]: ... def __len__(self) -> int: ... @@ -150,12 +145,8 @@ class CIMultiDictProxy(MultiMapping[istr, _T]): def getone(self, key: _S) -> _T: ... @overload def getone(self, key: _S, default: _D) -> Union[_T, _D]: ... + def copy(self) -> CIMultiDict[_T]: ... def getversion( - md: Union[ - MultiDict[_T], - CIMultiDict[_T], - MultiDictProxy[_T], - CIMultiDictProxy[_T], - ] + md: Union[MultiDict[_T], CIMultiDict[_T], MultiDictProxy[_T], CIMultiDictProxy[_T]] ) -> int: ...