Skip to content

Commit fe3534c

Browse files
authored
Revert #644, restore type annotations to as-of 5.2.0 version (#688)
1 parent 572ce02 commit fe3534c

File tree

6 files changed

+323
-65
lines changed

6 files changed

+323
-65
lines changed

CHANGES/688.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Revert :issue:`644`, restore type annotations to as-of 5.2.0 version.

Makefile

+10-9
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,36 @@ all: test
1212
@touch .install-deps
1313

1414
.flake: .install-deps $(shell find multidict -type f) \
15-
$(shell find tests -type f)
15+
$(shell find tests -type f)
1616
flake8 multidict tests
1717
@if ! isort --check multidict tests; then \
18-
echo "Import sort errors, run 'make fmt' to fix them!!!"; \
19-
isort --diff --check multidict tests; \
20-
false; \
18+
echo "Import sort errors, run 'make fmt' to fix them!!!"; \
19+
isort --diff --check multidict tests; \
20+
false; \
2121
fi
2222
@touch .flake
2323

2424

2525
isort-check:
2626
@if ! isort --check $(SRC); then \
27-
echo "Import sort errors, run 'make fmt' to fix them!!!"; \
28-
isort --diff --check $(SRC); \
29-
false; \
27+
echo "Import sort errors, run 'make fmt' to fix them!!!"; \
28+
isort --diff --check $(SRC); \
29+
false; \
3030
fi
3131

3232
flake8:
3333
flake8 $(SRC)
3434

3535
black-check:
3636
@if ! isort --check $(SRC); then \
37-
echo "black errors, run 'make fmt' to fix them!!!"; \
37+
echo "black errors, run 'make fmt' to fix them!!!"; \
3838
black -t py35 --diff --check $(SRC); \
39-
false; \
39+
false; \
4040
fi
4141

4242
mypy:
4343
mypy --show-error-codes multidict tests
44+
mypy --show-error-codes tests/test_mypy.py --strict
4445

4546
lint: flake8 black-check mypy isort-check check_changes
4647

multidict/__init__.pyi

+19-25
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class istr(str): ...
1717

1818
upstr = istr
1919

20-
_S = TypeVar("_S", str, istr)
20+
_S = Union[str, istr]
2121

2222
_T = TypeVar("_T")
2323

@@ -39,17 +39,16 @@ class MultiMapping(Mapping[_S, _T_co]):
3939
@abc.abstractmethod
4040
def getone(self, key: _S, default: _D) -> Union[_T_co, _D]: ...
4141

42-
_Arg = Union[
43-
Mapping[_S, _T], Dict[_S, _T], MultiMapping[_S, _T], Iterable[Tuple[_S, _T]]
44-
]
42+
_Arg = Union[Mapping[str, _T], Mapping[istr, _T],
43+
Dict[str, _T], Dict[istr, _T],
44+
MultiMapping[_T],
45+
Iterable[Tuple[str, _T]], Iterable[Tuple[istr, _T]]]
4546

46-
class MutableMultiMapping(
47-
MultiMapping[_S, _T], MutableMapping[_S, _T], Generic[_S, _T]
48-
):
47+
class MutableMultiMapping(MultiMapping[_T], MutableMapping[_S, _T], Generic[_T]):
4948
@abc.abstractmethod
5049
def add(self, key: _S, value: _T) -> None: ...
5150
@abc.abstractmethod
52-
def extend(self, arg: _Arg[_S, _T] = ..., **kwargs: _T) -> None: ...
51+
def extend(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
5352
@overload
5453
@abc.abstractmethod
5554
def popone(self, key: _S) -> _T: ...
@@ -63,8 +62,8 @@ class MutableMultiMapping(
6362
@abc.abstractmethod
6463
def popall(self, key: _S, default: _D) -> Union[List[_T], _D]: ...
6564

66-
class MultiDict(MutableMultiMapping[str, _T]):
67-
def __init__(self, arg: _Arg[_S, _T] = ..., **kwargs: _T) -> None: ...
65+
class MultiDict(MutableMultiMapping[_T], Generic[_T]):
66+
def __init__(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
6867
def copy(self) -> MultiDict[_T]: ...
6968
def __getitem__(self, k: _S) -> _T: ...
7069
def __setitem__(self, k: _S, v: _T) -> None: ...
@@ -80,7 +79,7 @@ class MultiDict(MutableMultiMapping[str, _T]):
8079
@overload
8180
def getone(self, key: _S, default: _D) -> Union[_T, _D]: ...
8281
def add(self, key: _S, value: _T) -> None: ...
83-
def extend(self, arg: _Arg[_S, _T] = ..., **kwargs: _T) -> None: ...
82+
def extend(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
8483
@overload
8584
def popone(self, key: _S) -> _T: ...
8685
@overload
@@ -90,8 +89,8 @@ class MultiDict(MutableMultiMapping[str, _T]):
9089
@overload
9190
def popall(self, key: _S, default: _D) -> Union[List[_T], _D]: ...
9291

93-
class CIMultiDict(MutableMultiMapping[istr, _T]):
94-
def __init__(self, arg: _Arg[_S, _T] = ..., **kwargs: _T) -> None: ...
92+
class CIMultiDict(MutableMultiMapping[_T], Generic[_T]):
93+
def __init__(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
9594
def copy(self) -> CIMultiDict[_T]: ...
9695
def __getitem__(self, k: _S) -> _T: ...
9796
def __setitem__(self, k: _S, v: _T) -> None: ...
@@ -107,7 +106,7 @@ class CIMultiDict(MutableMultiMapping[istr, _T]):
107106
@overload
108107
def getone(self, key: _S, default: _D) -> Union[_T, _D]: ...
109108
def add(self, key: _S, value: _T) -> None: ...
110-
def extend(self, arg: _Arg[_S, _T] = ..., **kwargs: _T) -> None: ...
109+
def extend(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
111110
@overload
112111
def popone(self, key: _S) -> _T: ...
113112
@overload
@@ -117,9 +116,9 @@ class CIMultiDict(MutableMultiMapping[istr, _T]):
117116
@overload
118117
def popall(self, key: _S, default: _D) -> Union[List[_T], _D]: ...
119118

120-
class MultiDictProxy(MultiMapping[str, _T]):
119+
class MultiDictProxy(MultiMapping[_T], Generic[_T]):
121120
def __init__(
122-
self, arg: Union[MultiDict[_T], MultiDictProxy[_T]]
121+
self, arg: Union[MultiMapping[_T], MutableMultiMapping[_T]]
123122
) -> None: ...
124123
def copy(self) -> MultiDict[_T]: ...
125124
def __getitem__(self, k: _S) -> _T: ...
@@ -134,11 +133,10 @@ class MultiDictProxy(MultiMapping[str, _T]):
134133
@overload
135134
def getone(self, key: _S, default: _D) -> Union[_T, _D]: ...
136135

137-
class CIMultiDictProxy(MultiMapping[istr, _T]):
136+
class CIMultiDictProxy(MultiMapping[_T], Generic[_T]):
138137
def __init__(
139-
self, arg: Union[CIMultiDict[_T], CIMultiDictProxy[_T]]
138+
self, arg: Union[MultiMapping[_T], MutableMultiMapping[_T]]
140139
) -> None: ...
141-
def copy(self) -> CIMultiDict[_T]: ...
142140
def __getitem__(self, k: _S) -> _T: ...
143141
def __iter__(self) -> Iterator[_S]: ...
144142
def __len__(self) -> int: ...
@@ -150,12 +148,8 @@ class CIMultiDictProxy(MultiMapping[istr, _T]):
150148
def getone(self, key: _S) -> _T: ...
151149
@overload
152150
def getone(self, key: _S, default: _D) -> Union[_T, _D]: ...
151+
def copy(self) -> CIMultiDict[_T]: ...
153152

154153
def getversion(
155-
md: Union[
156-
MultiDict[_T],
157-
CIMultiDict[_T],
158-
MultiDictProxy[_T],
159-
CIMultiDictProxy[_T],
160-
]
154+
md: Union[MultiDict[_T], CIMultiDict[_T], MultiDictProxy[_T], CIMultiDictProxy[_T]]
161155
) -> int: ...

0 commit comments

Comments
 (0)