mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-07-12 03:10:52 +08:00
Add @type_check_only to stub-only private classes in stdlib (#14512)
This commit is contained in:
@@ -7,7 +7,7 @@ from collections.abc import Callable, Container, Iterable, Mapping, Sequence, Se
|
||||
from contextlib import AbstractContextManager
|
||||
from re import Pattern
|
||||
from types import GenericAlias, TracebackType
|
||||
from typing import Any, AnyStr, Final, Generic, NoReturn, Protocol, SupportsAbs, SupportsRound, TypeVar, overload
|
||||
from typing import Any, AnyStr, Final, Generic, NoReturn, Protocol, SupportsAbs, SupportsRound, TypeVar, overload, type_check_only
|
||||
from typing_extensions import Never, ParamSpec, Self
|
||||
from unittest._log import _AssertLogsContext, _LoggingWatcher
|
||||
from warnings import WarningMessage
|
||||
@@ -56,6 +56,7 @@ def skipUnless(condition: object, reason: str) -> Callable[[_FT], _FT]: ...
|
||||
class SkipTest(Exception):
|
||||
def __init__(self, reason: str) -> None: ...
|
||||
|
||||
@type_check_only
|
||||
class _SupportsAbsAndDunderGE(SupportsDunderGE[Any], SupportsAbs[Any], Protocol): ...
|
||||
|
||||
class TestCase:
|
||||
|
||||
@@ -5,12 +5,13 @@ import unittest.result
|
||||
import unittest.suite
|
||||
from collections.abc import Iterable
|
||||
from types import ModuleType
|
||||
from typing import Any, Final, Protocol
|
||||
from typing import Any, Final, Protocol, type_check_only
|
||||
from typing_extensions import deprecated
|
||||
|
||||
MAIN_EXAMPLES: Final[str]
|
||||
MODULE_EXAMPLES: Final[str]
|
||||
|
||||
@type_check_only
|
||||
class _TestRunner(Protocol):
|
||||
def run(self, test: unittest.suite.TestSuite | unittest.case.TestCase, /) -> unittest.result.TestResult: ...
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ from _typeshed import MaybeNone
|
||||
from collections.abc import Awaitable, Callable, Coroutine, Iterable, Mapping, Sequence
|
||||
from contextlib import _GeneratorContextManager
|
||||
from types import TracebackType
|
||||
from typing import Any, ClassVar, Final, Generic, Literal, TypeVar, overload
|
||||
from typing import Any, ClassVar, Final, Generic, Literal, TypeVar, overload, type_check_only
|
||||
from typing_extensions import ParamSpec, Self, TypeAlias
|
||||
|
||||
_T = TypeVar("_T")
|
||||
@@ -262,6 +262,7 @@ class _patch(Generic[_T]):
|
||||
# This class does not exist at runtime, it's a hack to make this work:
|
||||
# @patch("foo")
|
||||
# def bar(..., mock: MagicMock) -> None: ...
|
||||
@type_check_only
|
||||
class _patch_pass_arg(_patch[_T]):
|
||||
@overload
|
||||
def __call__(self, func: _TT) -> _TT: ...
|
||||
@@ -288,6 +289,7 @@ class _patch_dict:
|
||||
|
||||
# This class does not exist at runtime, it's a hack to add methods to the
|
||||
# patch() function.
|
||||
@type_check_only
|
||||
class _patcher:
|
||||
TEST_PREFIX: str
|
||||
dict: type[_patch_dict]
|
||||
|
||||
@@ -4,15 +4,17 @@ import unittest.result
|
||||
import unittest.suite
|
||||
from _typeshed import SupportsFlush, SupportsWrite
|
||||
from collections.abc import Callable, Iterable
|
||||
from typing import Any, Generic, Protocol, TypeVar
|
||||
from typing import Any, Generic, Protocol, TypeVar, type_check_only
|
||||
from typing_extensions import Never, TypeAlias
|
||||
from warnings import _ActionKind
|
||||
|
||||
_ResultClassType: TypeAlias = Callable[[_TextTestStream, bool, int], TextTestResult[Any]]
|
||||
|
||||
@type_check_only
|
||||
class _SupportsWriteAndFlush(SupportsWrite[str], SupportsFlush, Protocol): ...
|
||||
|
||||
# All methods used by unittest.runner.TextTestResult's stream
|
||||
@type_check_only
|
||||
class _TextTestStream(_SupportsWriteAndFlush, Protocol):
|
||||
def writeln(self, arg: str | None = None, /) -> None: ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user