From b77fa8fd8b7ada62bf3b905e9ed70df8b1bb8313 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 19 Jul 2026 12:30:46 +0200 Subject: [PATCH 1/4] [_typeshed] Add `SupportsGet` Commonly useful protocol. This also allows us to document the `__get__` annotations in a central place. --- stdlib/_typeshed/__init__.pyi | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index 2f65d8aab9c5..e6f986d3e738 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -160,6 +160,16 @@ class SupportsTrunc(Protocol): # Mapping-like protocols +# The second and third overload could technically be combined, but splitting +# them works better with some type checkers. +class SupportsGet(Protocol[_KT_contra, _VT_co]): + @overload + def get(self, key: _KT_contra, /) -> _VT_co | None: ... + @overload + def get(self, key: _KT_contra, default: _VT_co, /) -> _VT_co: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter + @overload + def get(self, key: _KT_contra, default: _T, /) -> _VT_co | _T: ... + # stable class SupportsItems(Protocol[_KT_co, _VT_co]): def items(self) -> AbstractSet[tuple[_KT_co, _VT_co]]: ... From 78f90cff2e5d811988700dc699f8f9ea3394a30c Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 19 Jul 2026 12:33:02 +0200 Subject: [PATCH 2/4] Reshuffle the type ignores --- stdlib/_typeshed/__init__.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index e6f986d3e738..09788600ef00 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -162,11 +162,11 @@ class SupportsTrunc(Protocol): # The second and third overload could technically be combined, but splitting # them works better with some type checkers. -class SupportsGet(Protocol[_KT_contra, _VT_co]): +class SupportsGet(Protocol[_KT_contra, _VT_co]):# type: ignore[misc] # Covariant type as parameter @overload def get(self, key: _KT_contra, /) -> _VT_co | None: ... @overload - def get(self, key: _KT_contra, default: _VT_co, /) -> _VT_co: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter + def get(self, key: _KT_contra, default: _VT_co, /) -> _VT_co: ... # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter @overload def get(self, key: _KT_contra, default: _T, /) -> _VT_co | _T: ... From ea1eac8fc628d0795b79b20b5fe1a5393e4ed646 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 19 Jul 2026 10:35:50 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/_typeshed/__init__.pyi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index 09788600ef00..fddd80216a5c 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -162,11 +162,13 @@ class SupportsTrunc(Protocol): # The second and third overload could technically be combined, but splitting # them works better with some type checkers. -class SupportsGet(Protocol[_KT_contra, _VT_co]):# type: ignore[misc] # Covariant type as parameter +class SupportsGet(Protocol[_KT_contra, _VT_co]): # type: ignore[misc] # Covariant type as parameter @overload def get(self, key: _KT_contra, /) -> _VT_co | None: ... @overload - def get(self, key: _KT_contra, default: _VT_co, /) -> _VT_co: ... # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter + def get( + self, key: _KT_contra, default: _VT_co, / + ) -> _VT_co: ... # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter @overload def get(self, key: _KT_contra, default: _T, /) -> _VT_co | _T: ... From 254f9abad8c042f1f7b97ba9993ad15d40c88303 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sun, 19 Jul 2026 12:39:42 +0200 Subject: [PATCH 4/4] mypy is picky today --- stdlib/_typeshed/__init__.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index fddd80216a5c..6358ae64083c 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -167,8 +167,8 @@ class SupportsGet(Protocol[_KT_contra, _VT_co]): # type: ignore[misc] # Covaria def get(self, key: _KT_contra, /) -> _VT_co | None: ... @overload def get( - self, key: _KT_contra, default: _VT_co, / - ) -> _VT_co: ... # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter + self, key: _KT_contra, default: _VT_co, / # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter + ) -> _VT_co: ... @overload def get(self, key: _KT_contra, default: _T, /) -> _VT_co | _T: ...