diff --git a/stdlib/2/collections.pyi b/stdlib/2/collections.pyi index bd7420537..b4c94dd77 100644 --- a/stdlib/2/collections.pyi +++ b/stdlib/2/collections.pyi @@ -59,6 +59,8 @@ class deque(Sized, Iterable[_T], Reversible[_T], Generic[_T]): def __contains__(self, o: _T) -> bool: ... def __reversed__(self) -> Iterator[_T]: ... +_CounterT = TypeVar('_CounterT', bound=Counter) + class Counter(Dict[_T, int], Generic[_T]): @overload def __init__(self, **kwargs: int) -> None: ... @@ -66,6 +68,7 @@ class Counter(Dict[_T, int], Generic[_T]): def __init__(self, mapping: Mapping[_T, int]) -> None: ... @overload def __init__(self, iterable: Iterable[_T]) -> None: ... + def copy(self: _CounterT) -> _CounterT: ... def elements(self) -> Iterator[_T]: ... def most_common(self, n: Optional[int] = ...) -> List[Tuple[_T, int]]: ... @overload @@ -93,10 +96,14 @@ class Counter(Dict[_T, int], Generic[_T]): def __iand__(self, other: Counter[_T]) -> Counter[_T]: ... def __ior__(self, other: Counter[_T]) -> Counter[_T]: ... +_OrderedDictT = TypeVar('_OrderedDictT', bound=OrderedDict) + class OrderedDict(Dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]): def popitem(self, last: bool = ...) -> Tuple[_KT, _VT]: ... + def copy(self: _OrderedDictT) -> _OrderedDictT: ... def __reversed__(self) -> Iterator[_KT]: ... - def __copy__(self) -> OrderedDict[_KT, _VT]: ... + +_DefaultDictT = TypeVar('_DefaultDictT', bound=defaultdict) class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): default_factory = ... # type: Callable[[], _VT] @@ -111,3 +118,4 @@ class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): def __init__(self, default_factory: Optional[Callable[[], _VT]], iterable: Iterable[Tuple[_KT, _VT]]) -> None: ... def __missing__(self, key: _KT) -> _VT: ... + def copy(self: _DefaultDictT) -> _DefaultDictT: ... diff --git a/stdlib/3/collections/__init__.pyi b/stdlib/3/collections/__init__.pyi index d5e8f346a..88c2c95aa 100644 --- a/stdlib/3/collections/__init__.pyi +++ b/stdlib/3/collections/__init__.pyi @@ -236,6 +236,7 @@ class deque(MutableSequence[_T], Generic[_T]): def __mul__(self, other: int) -> deque[_T]: ... def __imul__(self, other: int) -> None: ... +_CounterT = TypeVar('_CounterT', bound=Counter) class Counter(Dict[_T, int], Generic[_T]): @overload @@ -244,7 +245,7 @@ class Counter(Dict[_T, int], Generic[_T]): def __init__(self, mapping: Mapping[_T, int]) -> None: ... @overload def __init__(self, iterable: Iterable[_T]) -> None: ... - + def copy(self: _CounterT) -> _CounterT: ... def elements(self) -> Iterator[_T]: ... def most_common(self, n: Optional[int] = ...) -> List[Tuple[_T, int]]: ... @@ -277,11 +278,15 @@ class Counter(Dict[_T, int], Generic[_T]): def __iand__(self, other: Counter[_T]) -> Counter[_T]: ... def __ior__(self, other: Counter[_T]) -> Counter[_T]: ... +_OrderedDictT = TypeVar('_OrderedDictT', bound=OrderedDict) + class OrderedDict(Dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]): def popitem(self, last: bool = ...) -> Tuple[_KT, _VT]: ... def move_to_end(self, key: _KT, last: bool = ...) -> None: ... + def copy(self: _OrderedDictT) -> _OrderedDictT: ... def __reversed__(self) -> Iterator[_KT]: ... - def __copy__(self) -> OrderedDict[_KT, _VT]: ... + +_DefaultDictT = TypeVar('_DefaultDictT', bound=defaultdict) class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): default_factory = ... # type: Callable[[], _VT] @@ -296,9 +301,9 @@ class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): @overload def __init__(self, default_factory: Optional[Callable[[], _VT]], iterable: Iterable[Tuple[_KT, _VT]]) -> None: ... - def __missing__(self, key: _KT) -> _VT: ... # TODO __reversed__ + def copy(self: _DefaultDictT) -> _DefaultDictT: ... if sys.version_info >= (3, 3): class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]):