Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
q0w committed Jan 19, 2022
1 parent 1322f1a commit 325d23d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
47 changes: 28 additions & 19 deletions multidict/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class istr(str): ...

upstr = istr

_S = Union[str, istr]
_S = TypeVar("_S", str, istr)

_T = TypeVar("_T")

Expand All @@ -39,13 +39,17 @@ 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[_T], Iterable[Tuple[_S, _T]]]
_Arg = Union[
Mapping[_S, _T], Dict[_S, _T], MultiMapping[_S, _T], Iterable[Tuple[_S, _T]]
]

class MutableMultiMapping(MultiMapping[_T], MutableMapping[_S, _T], Generic[_T]):
class MutableMultiMapping(
MultiMapping[_S, _T], MutableMapping[_S, _T], Generic[_S, _T]
):
@abc.abstractmethod
def add(self, key: _S, value: _T) -> None: ...
@abc.abstractmethod
def extend(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
def extend(self, arg: _Arg[_S, _T] = ..., **kwargs: _T) -> None: ...
@overload
@abc.abstractmethod
def popone(self, key: _S) -> _T: ...
Expand All @@ -59,9 +63,9 @@ class MutableMultiMapping(MultiMapping[_T], MutableMapping[_S, _T], Generic[_T])
@abc.abstractmethod
def popall(self, key: _S, default: _D) -> Union[List[_T], _D]: ...

class MultiDict(MutableMultiMapping[_T], Generic[_T]):
def __init__(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
def copy(self) -> MultiDict[_T]: ...
class MultiDict(MutableMultiMapping[_S, _T], Generic[_S, _T]):
def __init__(self, arg: _Arg[_S, _T] = ..., **kwargs: _T) -> None: ...
def copy(self) -> MultiDict[_S, _T]: ...
def __getitem__(self, k: _S) -> _T: ...
def __setitem__(self, k: _S, v: _T) -> None: ...
def __delitem__(self, v: _S) -> None: ...
Expand All @@ -76,7 +80,7 @@ class MultiDict(MutableMultiMapping[_T], Generic[_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[_T] = ..., **kwargs: _T) -> None: ...
def extend(self, arg: _Arg[_S, _T] = ..., **kwargs: _T) -> None: ...
@overload
def popone(self, key: _S) -> _T: ...
@overload
Expand All @@ -86,9 +90,9 @@ class MultiDict(MutableMultiMapping[_T], Generic[_T]):
@overload
def popall(self, key: _S, default: _D) -> Union[List[_T], _D]: ...

class CIMultiDict(MutableMultiMapping[_T], Generic[_T]):
def __init__(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
def copy(self) -> CIMultiDict[_T]: ...
class CIMultiDict(MutableMultiMapping[_S, _T], Generic[_S, _T]):
def __init__(self, arg: _Arg[_S, _T] = ..., **kwargs: _T) -> None: ...
def copy(self) -> CIMultiDict[_S, _T]: ...
def __getitem__(self, k: _S) -> _T: ...
def __setitem__(self, k: _S, v: _T) -> None: ...
def __delitem__(self, v: _S) -> None: ...
Expand All @@ -103,7 +107,7 @@ class CIMultiDict(MutableMultiMapping[_T], Generic[_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[_T] = ..., **kwargs: _T) -> None: ...
def extend(self, arg: _Arg[_S, _T] = ..., **kwargs: _T) -> None: ...
@overload
def popone(self, key: _S) -> _T: ...
@overload
Expand All @@ -113,11 +117,11 @@ class CIMultiDict(MutableMultiMapping[_T], Generic[_T]):
@overload
def popall(self, key: _S, default: _D) -> Union[List[_T], _D]: ...

class MultiDictProxy(MultiMapping[_T], Generic[_T]):
class MultiDictProxy(MultiMapping[_S, _T], Generic[_S, _T]):
def __init__(
self, arg: Union[MultiMapping[_T], MutableMultiMapping[_T]]
self, arg: Union[MultiMapping[_S, _T], MutableMultiMapping[_S, _T]]
) -> None: ...
def copy(self) -> MultiDict[_T]: ...
def copy(self) -> MultiDict[_S, _T]: ...
def __getitem__(self, k: _S) -> _T: ...
def __iter__(self) -> Iterator[_S]: ...
def __len__(self) -> int: ...
Expand All @@ -130,9 +134,9 @@ class MultiDictProxy(MultiMapping[_T], Generic[_T]):
@overload
def getone(self, key: _S, default: _D) -> Union[_T, _D]: ...

class CIMultiDictProxy(MultiMapping[_T], Generic[_T]):
class CIMultiDictProxy(MultiMapping[_S, _T], Generic[_S, _T]):
def __init__(
self, arg: Union[MultiMapping[_T], MutableMultiMapping[_T]]
self, arg: Union[MultiMapping[_S, _T], MutableMultiMapping[_S, _T]]
) -> None: ...
def __getitem__(self, k: _S) -> _T: ...
def __iter__(self) -> Iterator[_S]: ...
Expand All @@ -145,8 +149,13 @@ class CIMultiDictProxy(MultiMapping[_T], Generic[_T]):
def getone(self, key: _S) -> _T: ...
@overload
def getone(self, key: _S, default: _D) -> Union[_T, _D]: ...
def copy(self) -> CIMultiDict[_T]: ...
def copy(self) -> CIMultiDict[_S, _T]: ...

def getversion(
md: Union[MultiDict[_T], CIMultiDict[_T], MultiDictProxy[_T], CIMultiDictProxy[_T]]
md: Union[
MultiDict[_S, _T],
CIMultiDict[_S, _T],
MultiDictProxy[_S, _T],
CIMultiDictProxy[_S, _T],
]
) -> int: ...
4 changes: 2 additions & 2 deletions tests/test_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


def test_classes_not_abstract() -> None:
d1 = multidict.MultiDict({"a": "b"}) # type: multidict.MultiDict[str]
d2 = multidict.CIMultiDict({"a": "b"}) # type: multidict.CIMultiDict[str]
d1 = multidict.MultiDict({"a": "b"}) # type: multidict.MultiDict[str,str]
d2 = multidict.CIMultiDict({"a": "b"}) # type: multidict.CIMultiDict[str,str]

d3 = multidict.MultiDictProxy(d1)
d4 = multidict.CIMultiDictProxy(d2)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


class VersionMixin:
cls: Type[MultiMapping[str]]
cls: Type[MultiMapping[str, str]]

def getver(self, md):
raise NotImplementedError
Expand Down

0 comments on commit 325d23d

Please sign in to comment.