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
@@ -3,7 +3,7 @@ from _collections_abc import dict_keys, dict_values
from _typeshed import Incomplete, ReadableBuffer, SupportsRead, SupportsWrite
from collections.abc import Iterable, Sequence
from types import TracebackType
from typing import Any, ClassVar, Generic, Literal, NoReturn, Protocol, TypeVar, overload
from typing import Any, ClassVar, Generic, Literal, NoReturn, Protocol, TypeVar, overload, type_check_only
from typing_extensions import Self, TypeAlias
from xml.dom.minicompat import EmptyNodeList, NodeList
from xml.dom.xmlbuilder import DocumentLS, DOMImplementationLS
@@ -40,9 +40,11 @@ _ImportableNodeVar = TypeVar(
| Notation,
)
@type_check_only
class _DOMErrorHandler(Protocol):
def handleError(self, error: Exception) -> bool: ...
@type_check_only
class _UserDataHandler(Protocol):
def handle(self, operation: int, key: str, data: Any, src: Node, dst: Node) -> None: ...
+2 -1
View File
@@ -1,7 +1,8 @@
from _typeshed import FileDescriptorOrPath
from typing import Final, Literal, Protocol, overload
from typing import Final, Literal, Protocol, overload, type_check_only
from xml.etree.ElementTree import Element
@type_check_only
class _Loader(Protocol):
@overload
def __call__(self, href: FileDescriptorOrPath, parse: Literal["xml"], encoding: str | None = None) -> Element: ...
+1
View File
@@ -335,6 +335,7 @@ class C14NWriterTarget:
# The target type is tricky, because the implementation doesn't
# require any particular attribute to be present. This documents the attributes
# that can be present, but uncommenting any of them would require them.
@type_check_only
class _Target(Protocol):
# start: Callable[str, dict[str, str], Any] | None
# end: Callable[[str], Any] | None
+2 -1
View File
@@ -1,7 +1,7 @@
import sys
from _typeshed import ReadableBuffer, StrPath, SupportsRead, _T_co
from collections.abc import Iterable
from typing import Protocol
from typing import Protocol, type_check_only
from typing_extensions import TypeAlias
from xml.sax._exceptions import (
SAXException as SAXException,
@@ -13,6 +13,7 @@ from xml.sax._exceptions import (
from xml.sax.handler import ContentHandler as ContentHandler, ErrorHandler as ErrorHandler
from xml.sax.xmlreader import InputSource as InputSource, XMLReader
@type_check_only
class _SupportsReadClose(SupportsRead[_T_co], Protocol[_T_co]):
def close(self) -> None: ...