Skip to content

Commit 95eeb6b

Browse files
committed
Add checker, improve annotations
1 parent 1a78692 commit 95eeb6b

4 files changed

Lines changed: 44 additions & 41 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,5 @@ multidict/_istr.html
7474

7575
# test results in junit format for Appveyor
7676
/junit-test-results.xml
77+
78+
.pytest_cache

multidict/__init__.pyi

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from typing import Any, Mapping, MutableMapping, List, Union, Iterable
2-
from typing import KeysView, ValuesView, ItemsView, Iterator, Tuple
3-
from typing import overload, TypeVar, Generic, Optional
1+
from typing import (Mapping, MutableMapping, List, Union, Iterable,
2+
Iterator, TypeVar, Generic, Tuple, Dict)
43

54

6-
class istr(str): ...
5+
class istr(str):
6+
pass
7+
78

89
upstr = istr
910

@@ -12,87 +13,86 @@ _S = Union[str, istr]
1213
_T = TypeVar('_T')
1314

1415

15-
class MultiMapping(Mapping[_S, _T]):
16-
def getall(self, key: _S, default: _T=...) -> List[_T]: ...
17-
def getone(self, key: _S, default: _T=...) -> _T: ...
16+
class MultiMapping(Mapping[_S, _T], Generic[_T]):
17+
def getall(self, key: _S, default: _T = ...) -> List[_T]: ...
18+
19+
def getone(self, key: _S, default: _T = ...) -> _T: ...
20+
21+
22+
_Arg = Union[Mapping[_S, _T],
23+
Dict[_S, _T],
24+
MultiMapping[_T],
25+
Iterable[Tuple[_S. _T]]]
1826

1927

2028
class MutableMultiMapping(MultiMapping[_T],
21-
MutableMapping[_S, _T]):
29+
MutableMapping[_S, _T],
30+
Generic[_T]):
2231

2332
def add(self, key: _S, value: _T) -> None: ...
2433

25-
@overload
26-
def extend(self, dct: MultiDict[_T]) -> None: ...
27-
@overload
28-
def extend(self, map: Mapping[_S, _T]) -> None: ...
29-
@overload
30-
def extend(self, iterable: Iterable[Tuple[_S, _T]]) -> None: ...
34+
def extend(self, arg: _Arg = ..., **kwargs: _T) -> None: ...
3135

32-
@overload
33-
def popone(self, key: _S) -> _T: ...
34-
@overload
35-
def popone(self, key: _S, default: _T=...) -> _T: ...
36+
def popone(self, key: _S, default: _T = ...) -> _T: ...
3637

37-
@overload
38-
def popall(self, key: _S) -> List[_T]: ...
39-
@overload
40-
def popall(self, key: _S, default: _T=...) -> List[_T]: ...
38+
def popall(self, key: _S, default: _T = ...) -> List[_T]: ...
4139

4240

43-
class MultiDict(MutableMultiMapping[_T]):
44-
@overload
45-
def __init__(self) -> None: ...
46-
@overload
47-
def __init__(self, map: Mapping[_S, _T]) -> None: ...
48-
@overload
49-
def __init__(self, iterable: Iterable[Tuple[_S, _T]]) -> None: ...
41+
class MultiDict(MutableMultiMapping[_T], Generic[_T]):
42+
def __init__(self, arg: _Arg = ..., **kwargs: _T) -> None: ...
5043

5144
def copy(self) -> MultiDict[_T]: ...
5245

53-
5446
def __getitem__(self, k: _S) -> _T: ...
47+
5548
def __setitem__(self, k: _S, v: _T) -> None: ...
49+
5650
def __delitem__(self, v: _S) -> None: ...
51+
5752
def __iter__(self) -> Iterator[_S]: ...
53+
5854
def __len__(self) -> int: ...
5955

6056

61-
class CIMultiDict(MutableMultiMapping[_T]):
62-
@overload
63-
def __init__(self) -> None: ...
64-
@overload
65-
def __init__(self, map: Mapping[_S, _T]) -> None: ...
66-
@overload
67-
def __init__(self, iterable: Iterable[Tuple[_S, _T]]) -> None: ...
57+
class CIMultiDict(MutableMultiMapping[_T], Generic[_T]):
58+
def __init__(self, arg: _Arg = ..., **kwargs: _T) -> None: ...
6859

6960
def copy(self) -> CIMultiDict[_T]: ...
7061

7162
def __getitem__(self, k: _S) -> _T: ...
63+
7264
def __setitem__(self, k: _S, v: _T) -> None: ...
65+
7366
def __delitem__(self, v: _S) -> None: ...
67+
7468
def __iter__(self) -> Iterator[_S]: ...
69+
7570
def __len__(self) -> int: ...
7671

7772

78-
class MultiDictProxy(MultiMapping[_T]):
73+
class MultiDictProxy(MultiMapping[_T], Generic[_T]):
7974
def __init__(self, arg: Union[MultiMapping[_T],
8075
MutableMultiMapping[_T]]) -> None: ...
8176

8277
def copy(self) -> MultiDictProxy[_T]: ...
8378

8479
def __getitem__(self, k: _S) -> _T: ...
80+
8581
def __iter__(self) -> Iterator[_S]: ...
82+
8683
def __len__(self) -> int: ...
8784

8885

89-
class CIMultiDictProxy(MultiMapping[_T]):
86+
class CIMultiDictProxy(MultiMapping[_T], Generic[_T]):
9087
def __init__(self, arg: Union[MultiMapping[_T],
9188
MutableMultiMapping[_T]]) -> None: ...
89+
9290
def copy(self) -> CIMultiDictProxy[_T]: ...
9391

9492
def __getitem__(self, k: _S) -> _T: ...
93+
9594
def __iter__(self) -> Iterator[_S]: ...
95+
9696
def __len__(self) -> int: ...
9797

9898

requirements/ci.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
-r wheel.txt
22
flake8==3.5.0
3+
flake8-pyi==18.3.1
34
pyflakes>=1.0.0
45
coverage==4.5.1
56
sphinx==1.7.4

tests/test_mypy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33

44
def test_classes_not_abstract() -> None:
5-
d1 = multidict.MultiDict({'a': 'b'})
6-
d2 = multidict.CIMultiDict({'a': 'b'})
5+
d1 = multidict.MultiDict({'a': 'b'}) # type: multidict.MultiDict[str]
6+
d2 = multidict.CIMultiDict({'a': 'b'}) # type: multidict.CIMultiDict[str]
77

88
d3 = multidict.MultiDictProxy(d1)
99
d4 = multidict.CIMultiDictProxy(d2)

0 commit comments

Comments
 (0)