Skip to content

Commit

Permalink
Revert #644, restore type annotations to as-of 5.2.0 version (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov authored Jan 24, 2022
1 parent 572ce02 commit fe3534c
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 65 deletions.
1 change: 1 addition & 0 deletions CHANGES/688.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Revert :issue:`644`, restore type annotations to as-of 5.2.0 version.
19 changes: 10 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,36 @@ all: test
@touch .install-deps

.flake: .install-deps $(shell find multidict -type f) \
$(shell find tests -type f)
$(shell find tests -type f)
flake8 multidict tests
@if ! isort --check multidict tests; then \
echo "Import sort errors, run 'make fmt' to fix them!!!"; \
isort --diff --check multidict tests; \
false; \
echo "Import sort errors, run 'make fmt' to fix them!!!"; \
isort --diff --check multidict tests; \
false; \
fi
@touch .flake


isort-check:
@if ! isort --check $(SRC); then \
echo "Import sort errors, run 'make fmt' to fix them!!!"; \
isort --diff --check $(SRC); \
false; \
echo "Import sort errors, run 'make fmt' to fix them!!!"; \
isort --diff --check $(SRC); \
false; \
fi

flake8:
flake8 $(SRC)

black-check:
@if ! isort --check $(SRC); then \
echo "black errors, run 'make fmt' to fix them!!!"; \
echo "black errors, run 'make fmt' to fix them!!!"; \
black -t py35 --diff --check $(SRC); \
false; \
false; \
fi

mypy:
mypy --show-error-codes multidict tests
mypy --show-error-codes tests/test_mypy.py --strict

lint: flake8 black-check mypy isort-check check_changes

Expand Down
44 changes: 19 additions & 25 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 = TypeVar("_S", str, istr)
_S = Union[str, istr]

_T = TypeVar("_T")

Expand All @@ -39,17 +39,16 @@ 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[str, _T], Mapping[istr, _T],
Dict[str, _T], Dict[istr, _T],
MultiMapping[_T],
Iterable[Tuple[str, _T]], Iterable[Tuple[istr, _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: ...
Expand All @@ -63,8 +62,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: ...
Expand All @@ -80,7 +79,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
Expand All @@ -90,8 +89,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: ...
Expand All @@ -107,7 +106,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
Expand All @@ -117,9 +116,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: ...
Expand All @@ -134,11 +133,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: ...
Expand All @@ -150,12 +148,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: ...
Loading

0 comments on commit fe3534c

Please sign in to comment.