1 # Stubs for collections
\r
3 # Based on http://docs.python.org/2.7/library/collections.html
\r
5 # These are not exported.
\r
7 from typing import Dict, Generic, TypeVar, Tuple, overload, Type, Optional, List, Union, Reversible
\r
9 # These are exported.
\r
10 from typing import (
\r
11 Callable as Callable,
\r
12 Container as Container,
\r
13 Hashable as Hashable,
\r
14 ItemsView as ItemsView,
\r
15 Iterable as Iterable,
\r
16 Iterator as Iterator,
\r
17 KeysView as KeysView,
\r
19 MappingView as MappingView,
\r
20 MutableMapping as MutableMapping,
\r
21 MutableSequence as MutableSequence,
\r
22 MutableSet as MutableSet,
\r
23 Sequence as Sequence,
\r
26 ValuesView as ValuesView,
\r
30 _KT = TypeVar('_KT')
\r
31 _VT = TypeVar('_VT')
\r
33 # namedtuple is special-cased in the type checker; the initializer is ignored.
\r
34 def namedtuple(typename: Union[str, unicode], field_names: Union[str, unicode, Iterable[Union[str, unicode]]], *,
\r
35 verbose: bool = ..., rename: bool = ...) -> Type[tuple]: ...
\r
37 class deque(Sized, Iterable[_T], Reversible[_T], Generic[_T]):
\r
38 def __init__(self, iterable: Iterable[_T] = ...,
\r
39 maxlen: int = ...) -> None: ...
\r
41 def maxlen(self) -> Optional[int]: ...
\r
42 def append(self, x: _T) -> None: ...
\r
43 def appendleft(self, x: _T) -> None: ...
\r
44 def clear(self) -> None: ...
\r
45 def count(self, x: _T) -> int: ...
\r
46 def extend(self, iterable: Iterable[_T]) -> None: ...
\r
47 def extendleft(self, iterable: Iterable[_T]) -> None: ...
\r
48 def pop(self) -> _T: ...
\r
49 def popleft(self) -> _T: ...
\r
50 def remove(self, value: _T) -> None: ...
\r
51 def reverse(self) -> None: ...
\r
52 def rotate(self, n: int) -> None: ...
\r
53 def __len__(self) -> int: ...
\r
54 def __iter__(self) -> Iterator[_T]: ...
\r
55 def __str__(self) -> str: ...
\r
56 def __hash__(self) -> int: ...
\r
57 def __getitem__(self, i: int) -> _T: ...
\r
58 def __setitem__(self, i: int, x: _T) -> None: ...
\r
59 def __contains__(self, o: _T) -> bool: ...
\r
60 def __reversed__(self) -> Iterator[_T]: ...
\r
62 _CounterT = TypeVar('_CounterT', bound=Counter)
\r
64 class Counter(Dict[_T, int], Generic[_T]):
\r
66 def __init__(self, **kwargs: int) -> None: ...
\r
68 def __init__(self, mapping: Mapping[_T, int]) -> None: ...
\r
70 def __init__(self, iterable: Iterable[_T]) -> None: ...
\r
71 def copy(self: _CounterT) -> _CounterT: ...
\r
72 def elements(self) -> Iterator[_T]: ...
\r
73 def most_common(self, n: Optional[int] = ...) -> List[Tuple[_T, int]]: ...
\r
75 def subtract(self, __mapping: Mapping[_T, int]) -> None: ...
\r
77 def subtract(self, iterable: Iterable[_T]) -> None: ...
\r
78 # The Iterable[Tuple[...]] argument type is not actually desirable
\r
79 # (the tuples will be added as keys, breaking type safety) but
\r
80 # it's included so that the signature is compatible with
\r
81 # Dict.update. Not sure if we should use '# type: ignore' instead
\r
82 # and omit the type from the union.
\r
84 def update(self, __m: Mapping[_T, int], **kwargs: int) -> None: ...
\r
86 def update(self, __m: Union[Iterable[_T], Iterable[Tuple[_T, int]]], **kwargs: int) -> None: ...
\r
88 def update(self, **kwargs: int) -> None: ...
\r
90 def __add__(self, other: Counter[_T]) -> Counter[_T]: ...
\r
91 def __sub__(self, other: Counter[_T]) -> Counter[_T]: ...
\r
92 def __and__(self, other: Counter[_T]) -> Counter[_T]: ...
\r
93 def __or__(self, other: Counter[_T]) -> Counter[_T]: ...
\r
94 def __iadd__(self, other: Counter[_T]) -> Counter[_T]: ...
\r
95 def __isub__(self, other: Counter[_T]) -> Counter[_T]: ...
\r
96 def __iand__(self, other: Counter[_T]) -> Counter[_T]: ...
\r
97 def __ior__(self, other: Counter[_T]) -> Counter[_T]: ...
\r
99 _OrderedDictT = TypeVar('_OrderedDictT', bound=OrderedDict)
\r
101 class OrderedDict(Dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
\r
102 def popitem(self, last: bool = ...) -> Tuple[_KT, _VT]: ...
\r
103 def copy(self: _OrderedDictT) -> _OrderedDictT: ...
\r
104 def __reversed__(self) -> Iterator[_KT]: ...
\r
106 _DefaultDictT = TypeVar('_DefaultDictT', bound=defaultdict)
\r
108 class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]):
\r
109 default_factory = ... # type: Callable[[], _VT]
\r
111 def __init__(self, **kwargs: _VT) -> None: ...
\r
113 def __init__(self, default_factory: Optional[Callable[[], _VT]]) -> None: ...
\r
115 def __init__(self, default_factory: Optional[Callable[[], _VT]], **kwargs: _VT) -> None: ...
\r
117 def __init__(self, default_factory: Optional[Callable[[], _VT]],
\r
118 map: Mapping[_KT, _VT]) -> None: ...
\r
120 def __init__(self, default_factory: Optional[Callable[[], _VT]],
\r
121 map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ...
\r
123 def __init__(self, default_factory: Optional[Callable[[], _VT]],
\r
124 iterable: Iterable[Tuple[_KT, _VT]]) -> None: ...
\r
126 def __init__(self, default_factory: Optional[Callable[[], _VT]],
\r
127 iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
\r
128 def __missing__(self, key: _KT) -> _VT: ...
\r
129 def copy(self: _DefaultDictT) -> _DefaultDictT: ...
\r