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
+3 -1
View File
@@ -7,7 +7,7 @@ from re import Pattern
from string import Template
from time import struct_time
from types import FrameType, GenericAlias, TracebackType
from typing import Any, ClassVar, Final, Generic, Literal, Protocol, TextIO, TypeVar, overload
from typing import Any, ClassVar, Final, Generic, Literal, Protocol, TextIO, TypeVar, overload, type_check_only
from typing_extensions import Self, TypeAlias, deprecated
__all__ = [
@@ -67,11 +67,13 @@ _Level: TypeAlias = int | str
_FormatStyle: TypeAlias = Literal["%", "{", "$"]
if sys.version_info >= (3, 12):
@type_check_only
class _SupportsFilter(Protocol):
def filter(self, record: LogRecord, /) -> bool | LogRecord: ...
_FilterType: TypeAlias = Filter | Callable[[LogRecord], bool | LogRecord] | _SupportsFilter
else:
@type_check_only
class _SupportsFilter(Protocol):
def filter(self, record: LogRecord, /) -> bool: ...
+2 -1
View File
@@ -9,7 +9,7 @@ from re import Pattern
from socket import SocketKind, socket
from threading import Thread
from types import TracebackType
from typing import Any, ClassVar, Final, Protocol, TypeVar
from typing import Any, ClassVar, Final, Protocol, TypeVar, type_check_only
from typing_extensions import Self
_T = TypeVar("_T")
@@ -225,6 +225,7 @@ class HTTPHandler(Handler):
def mapLogRecord(self, record: LogRecord) -> dict[str, Any]: ...
def getConnection(self, host: str, secure: bool) -> http.client.HTTPConnection: ... # undocumented
@type_check_only
class _QueueLike(Protocol[_T]):
def get(self) -> _T: ...
def put_nowait(self, item: _T, /) -> None: ...