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

This commit is contained in:
Brian Schubert
2025-08-03 04:13:16 -04:00
committed by GitHub
parent dde70aeecd
commit 622df68c1c
61 changed files with 188 additions and 51 deletions
+4 -1
View File
@@ -8,7 +8,7 @@
# nor `float` as a subtype of `numbers.Real`, etc.)
from abc import ABCMeta, abstractmethod
from typing import ClassVar, Literal, Protocol, overload
from typing import ClassVar, Literal, Protocol, overload, type_check_only
__all__ = ["Number", "Complex", "Real", "Rational", "Integral"]
@@ -22,6 +22,7 @@ __all__ = ["Number", "Complex", "Real", "Rational", "Integral"]
# NOTE: We can't include `__complex__` here,
# as we want `int` to be seen as a subtype of `_ComplexLike`,
# and `int.__complex__` does not exist :(
@type_check_only
class _ComplexLike(Protocol):
def __neg__(self) -> _ComplexLike: ...
def __pos__(self) -> _ComplexLike: ...
@@ -29,6 +30,7 @@ class _ComplexLike(Protocol):
# _RealLike is a structural-typing approximation
# of the `Real` ABC, which is not (and cannot be) a protocol
@type_check_only
class _RealLike(_ComplexLike, Protocol):
def __trunc__(self) -> _IntegralLike: ...
def __floor__(self) -> _IntegralLike: ...
@@ -41,6 +43,7 @@ class _RealLike(_ComplexLike, Protocol):
# _IntegralLike is a structural-typing approximation
# of the `Integral` ABC, which is not (and cannot be) a protocol
@type_check_only
class _IntegralLike(_RealLike, Protocol):
def __invert__(self) -> _IntegralLike: ...
def __int__(self) -> int: ...