Skip to content

Commit 3542650

Browse files
authored
Covariant key type for MappingProxyType (#13940)
1 parent f033cf1 commit 3542650

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

stdlib/types.pyi

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ if sys.version_info >= (3, 13):
6565

6666
_T1 = TypeVar("_T1")
6767
_T2 = TypeVar("_T2")
68-
_KT = TypeVar("_KT")
68+
_KT_co = TypeVar("_KT_co", covariant=True)
6969
_VT_co = TypeVar("_VT_co", covariant=True)
7070

7171
# Make sure this class definition stays roughly in line with `builtins.function`
@@ -309,27 +309,27 @@ class CodeType:
309309
__replace__ = replace
310310

311311
@final
312-
class MappingProxyType(Mapping[_KT, _VT_co]):
312+
class MappingProxyType(Mapping[_KT_co, _VT_co]): # type: ignore[type-var] # pyright: ignore[reportInvalidTypeArguments]
313313
__hash__: ClassVar[None] # type: ignore[assignment]
314-
def __new__(cls, mapping: SupportsKeysAndGetItem[_KT, _VT_co]) -> Self: ...
315-
def __getitem__(self, key: _KT, /) -> _VT_co: ...
316-
def __iter__(self) -> Iterator[_KT]: ...
314+
def __new__(cls, mapping: SupportsKeysAndGetItem[_KT_co, _VT_co]) -> Self: ...
315+
def __getitem__(self, key: _KT_co, /) -> _VT_co: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
316+
def __iter__(self) -> Iterator[_KT_co]: ...
317317
def __len__(self) -> int: ...
318318
def __eq__(self, value: object, /) -> bool: ...
319-
def copy(self) -> dict[_KT, _VT_co]: ...
320-
def keys(self) -> KeysView[_KT]: ...
319+
def copy(self) -> dict[_KT_co, _VT_co]: ...
320+
def keys(self) -> KeysView[_KT_co]: ...
321321
def values(self) -> ValuesView[_VT_co]: ...
322-
def items(self) -> ItemsView[_KT, _VT_co]: ...
322+
def items(self) -> ItemsView[_KT_co, _VT_co]: ...
323323
@overload
324-
def get(self, key: _KT, /) -> _VT_co | None: ...
324+
def get(self, key: _KT_co, /) -> _VT_co | None: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter
325325
@overload
326-
def get(self, key: _KT, default: _VT_co, /) -> _VT_co: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter
326+
def get(self, key: _KT_co, default: _VT_co, /) -> _VT_co: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter
327327
@overload
328-
def get(self, key: _KT, default: _T2, /) -> _VT_co | _T2: ...
328+
def get(self, key: _KT_co, default: _T2, /) -> _VT_co | _T2: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter
329329
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
330-
def __reversed__(self) -> Iterator[_KT]: ...
331-
def __or__(self, value: Mapping[_T1, _T2], /) -> dict[_KT | _T1, _VT_co | _T2]: ...
332-
def __ror__(self, value: Mapping[_T1, _T2], /) -> dict[_KT | _T1, _VT_co | _T2]: ...
330+
def __reversed__(self) -> Iterator[_KT_co]: ...
331+
def __or__(self, value: Mapping[_T1, _T2], /) -> dict[_KT_co | _T1, _VT_co | _T2]: ...
332+
def __ror__(self, value: Mapping[_T1, _T2], /) -> dict[_KT_co | _T1, _VT_co | _T2]: ...
333333

334334
if sys.version_info >= (3, 12):
335335
@disjoint_base

0 commit comments

Comments
 (0)