Skip to content

Commit

Permalink
support anything with .keys() and __getitem__ in dict.__init__ (#4470)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli authored Aug 24, 2020
1 parent 39ddef2 commit c065982
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion stdlib/2/__builtin__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ from _typeshed import (
OpenBinaryModeWriting,
OpenTextMode,
ReadableBuffer,
SupportsKeysAndGetItem,
SupportsWrite,
)
from abc import ABCMeta
Expand Down Expand Up @@ -1001,7 +1002,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
@overload
def __init__(self, **kwargs: _VT) -> None: ...
@overload
def __init__(self, map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ...
def __init__(self, map: SupportsKeysAndGetItem[_KT, _VT], **kwargs: _VT) -> None: ...
@overload
def __init__(self, iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
def __new__(cls: Type[_T1], *args: Any, **kwargs: Any) -> _T1: ...
Expand Down
7 changes: 6 additions & 1 deletion stdlib/2and3/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
import array
import mmap
import sys
from typing import AbstractSet, Container, Protocol, Text, Tuple, TypeVar, Union
from typing import AbstractSet, Container, Iterable, Protocol, Text, Tuple, TypeVar, Union
from typing_extensions import Literal

_KT = TypeVar("_KT")
_KT_co = TypeVar("_KT_co", covariant=True)
_KT_contra = TypeVar("_KT_contra", contravariant=True)
_VT = TypeVar("_VT")
Expand All @@ -30,6 +31,10 @@ _T_contra = TypeVar("_T_contra", contravariant=True)
class SupportsItems(Protocol[_KT_co, _VT_co]):
def items(self) -> AbstractSet[Tuple[_KT_co, _VT_co]]: ...

class SupportsKeysAndGetItem(Protocol[_KT, _VT_co]):
def keys(self) -> Iterable[_KT]: ...
def __getitem__(self, __k: _KT) -> _VT_co: ...

class SupportsGetItem(Container[_KT_contra], Protocol[_KT_contra, _VT_co]):
def __getitem__(self, __k: _KT_contra) -> _VT_co: ...

Expand Down
3 changes: 2 additions & 1 deletion stdlib/2and3/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ from _typeshed import (
OpenBinaryModeWriting,
OpenTextMode,
ReadableBuffer,
SupportsKeysAndGetItem,
SupportsWrite,
)
from abc import ABCMeta
Expand Down Expand Up @@ -1001,7 +1002,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
@overload
def __init__(self, **kwargs: _VT) -> None: ...
@overload
def __init__(self, map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ...
def __init__(self, map: SupportsKeysAndGetItem[_KT, _VT], **kwargs: _VT) -> None: ...
@overload
def __init__(self, iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
def __new__(cls: Type[_T1], *args: Any, **kwargs: Any) -> _T1: ...
Expand Down

0 comments on commit c065982

Please sign in to comment.