Collections that inherit from dict should should override copy() (#1856)

Solves issue #1642. A previous attempt at this, #1656,
added __copy__ but omitted copy, and it did not properly use self-type.
This commit is contained in:
Chad Dombrova
2018-02-08 16:26:37 -08:00
committed by Ivan Levkivskyi
parent 9c04490e92
commit ed9d08e93b
2 changed files with 17 additions and 4 deletions

View File

@@ -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: ...