Add @type_check_only to stub-only private classes in stdlib (#14512)

This commit is contained in:
Brian Schubert
2025-08-03 10:13:16 +02:00
committed by GitHub
parent dde70aeecd
commit 622df68c1c
61 changed files with 188 additions and 51 deletions
+11 -2
View File
@@ -1340,6 +1340,9 @@ class property:
def __set__(self, instance: Any, value: Any, /) -> None: ...
def __delete__(self, instance: Any, /) -> None: ...
# This class does not exist at runtime, but stubtest complains if it's marked as
# @type_check_only because it has an alias that does exist at runtime. See mypy#19568.
# @type_check_only
@final
class _NotImplementedType(Any):
__call__: None
@@ -1513,7 +1516,7 @@ help: _sitebuiltins._Helper
def hex(number: int | SupportsIndex, /) -> str: ...
def id(obj: object, /) -> int: ...
def input(prompt: object = "", /) -> str: ...
@type_check_only
class _GetItemIterable(Protocol[_T_co]):
def __getitem__(self, i: int, /) -> _T_co: ...
@@ -1768,7 +1771,7 @@ def open(
opener: _Opener | None = None,
) -> IO[Any]: ...
def ord(c: str | bytes | bytearray, /) -> int: ...
@type_check_only
class _SupportsWriteAndFlush(SupportsWrite[_T_contra], SupportsFlush, Protocol[_T_contra]): ...
@overload
@@ -1787,12 +1790,15 @@ def print(
_E_contra = TypeVar("_E_contra", contravariant=True)
_M_contra = TypeVar("_M_contra", contravariant=True)
@type_check_only
class _SupportsPow2(Protocol[_E_contra, _T_co]):
def __pow__(self, other: _E_contra, /) -> _T_co: ...
@type_check_only
class _SupportsPow3NoneOnly(Protocol[_E_contra, _T_co]):
def __pow__(self, other: _E_contra, modulo: None = None, /) -> _T_co: ...
@type_check_only
class _SupportsPow3(Protocol[_E_contra, _M_contra, _T_co]):
def __pow__(self, other: _E_contra, modulo: _M_contra, /) -> _T_co: ...
@@ -1857,9 +1863,11 @@ def repr(obj: object, /) -> str: ...
# and https://github.com/python/typeshed/pull/9151
# on why we don't use `SupportsRound` from `typing.pyi`
@type_check_only
class _SupportsRound1(Protocol[_T_co]):
def __round__(self) -> _T_co: ...
@type_check_only
class _SupportsRound2(Protocol[_T_co]):
def __round__(self, ndigits: int, /) -> _T_co: ...
@@ -1881,6 +1889,7 @@ def sorted(iterable: Iterable[_T], /, *, key: Callable[[_T], SupportsRichCompari
_AddableT1 = TypeVar("_AddableT1", bound=SupportsAdd[Any, Any])
_AddableT2 = TypeVar("_AddableT2", bound=SupportsAdd[Any, Any])
@type_check_only
class _SupportsSumWithNoDefaultGiven(SupportsAdd[Any, Any], SupportsRAdd[int, Any], Protocol): ...
_SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWithNoDefaultGiven)