@@ -21,7 +21,7 @@ from _typeshed import (
21
21
)
22
22
from ast import AST , mod
23
23
from io import BufferedRandom , BufferedReader , BufferedWriter , FileIO , TextIOWrapper
24
- from types import CodeType , TracebackType
24
+ from types import CodeType , MappingProxyType , TracebackType
25
25
from typing import (
26
26
IO ,
27
27
AbstractSet ,
@@ -73,6 +73,8 @@ _T_co = TypeVar("_T_co", covariant=True)
73
73
_T_contra = TypeVar ("_T_contra" , contravariant = True )
74
74
_KT = TypeVar ("_KT" )
75
75
_VT = TypeVar ("_VT" )
76
+ _KT_co = TypeVar ("_KT_co" , covariant = True ) # Key type covariant containers.
77
+ _VT_co = TypeVar ("_VT_co" , covariant = True ) # Value type covariant containers.
76
78
_S = TypeVar ("_S" )
77
79
_T1 = TypeVar ("_T1" )
78
80
_T2 = TypeVar ("_T2" )
@@ -787,6 +789,20 @@ class list(MutableSequence[_T], Generic[_T]):
787
789
if sys .version_info >= (3 , 9 ):
788
790
def __class_getitem__ (cls , item : Any ) -> GenericAlias : ...
789
791
792
+ class _dict_keys (KeysView [_KT_co ], Generic [_KT_co , _VT_co ]):
793
+ if sys .version_info >= (3 , 10 ):
794
+ mapping : MappingProxyType [_KT_co , _VT_co ]
795
+
796
+ # The generics are the wrong way around because of a mypy limitation
797
+ # https://github.com/python/mypy/issues/11138
798
+ class _dict_values (ValuesView [_VT_co ], Generic [_VT_co , _KT_co ]):
799
+ if sys .version_info >= (3 , 10 ):
800
+ mapping : MappingProxyType [_KT_co , _VT_co ]
801
+
802
+ class _dict_items (ItemsView [_KT_co , _VT_co ], Generic [_KT_co , _VT_co ]):
803
+ if sys .version_info >= (3 , 10 ):
804
+ mapping : MappingProxyType [_KT_co , _VT_co ]
805
+
790
806
class dict (MutableMapping [_KT , _VT ], Generic [_KT , _VT ]):
791
807
@overload
792
808
def __init__ (self : dict [_KT , _VT ]) -> None : ...
@@ -807,9 +823,9 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
807
823
def update (self , __m : Iterable [Tuple [_KT , _VT ]], ** kwargs : _VT ) -> None : ...
808
824
@overload
809
825
def update (self , ** kwargs : _VT ) -> None : ...
810
- def keys (self ) -> KeysView [_KT ]: ...
811
- def values (self ) -> ValuesView [_VT ]: ...
812
- def items (self ) -> ItemsView [_KT , _VT ]: ...
826
+ def keys (self ) -> _dict_keys [_KT , _VT ]: ...
827
+ def values (self ) -> _dict_values [_VT , _KT ]: ...
828
+ def items (self ) -> _dict_items [_KT , _VT ]: ...
813
829
@classmethod
814
830
@overload
815
831
def fromkeys (cls , __iterable : Iterable [_T ], __value : None = ...) -> dict [_T , Any | None ]: ...
0 commit comments