Add @type_check_only to stub-only private classes in various third-party stubs (#15535)

This commit is contained in:
Semyon Moroz
2026-03-22 02:02:17 +04:00
committed by GitHub
parent 222da0600f
commit 282b1a838a
15 changed files with 56 additions and 18 deletions
+2 -1
View File
@@ -1,7 +1,8 @@
from collections.abc import Callable
from typing import Final, Literal, TypedDict
from typing import Final, Literal, TypedDict, type_check_only
from typing_extensions import TypeAlias
@type_check_only
class _RPi_Info(TypedDict):
P1_REVISION: int
REVISION: str
+3 -1
View File
@@ -1,10 +1,11 @@
from typing import Protocol, TypeVar, overload
from typing import Protocol, TypeVar, overload, type_check_only
from typing_extensions import TypeAlias
_T = TypeVar("_T")
_GetterReturnType_co = TypeVar("_GetterReturnType_co", covariant=True)
_SetterValueType_contra = TypeVar("_SetterValueType_contra", contravariant=True)
@type_check_only
class AsymmetricProperty(Protocol[_GetterReturnType_co, _SetterValueType_contra]):
@overload
def __get__(self, obj: None, type: type[object] | None = ..., /) -> property: ...
@@ -12,6 +13,7 @@ class AsymmetricProperty(Protocol[_GetterReturnType_co, _SetterValueType_contra]
def __get__(self, obj: object, type: type[object] | None = ..., /) -> _GetterReturnType_co: ...
def __set__(self, obj: object, value: _SetterValueType_contra, /) -> None: ...
@type_check_only
class AsymmetricPropertyWithDelete(
AsymmetricProperty[_GetterReturnType_co, _SetterValueType_contra], Protocol[_GetterReturnType_co, _SetterValueType_contra]
):
+2 -1
View File
@@ -1,6 +1,6 @@
from _typeshed import Incomplete
from collections.abc import Iterable, Mapping
from typing import Final, Literal, TypedDict, TypeVar, overload
from typing import Final, Literal, TypedDict, TypeVar, overload, type_check_only
from .healthcheck import Healthcheck
@@ -75,6 +75,7 @@ class Mount(dict[str, Incomplete]):
@classmethod
def parse_mount_string(cls, string: str) -> Mount: ...
@type_check_only
class _ResourceDict(TypedDict):
Kind: str
Value: int
+2 -1
View File
@@ -1,4 +1,4 @@
from typing import Any, ClassVar, Final, NamedTuple
from typing import Any, ClassVar, Final, NamedTuple, type_check_only
from typing_extensions import Self
from docutils.transforms import Transform
@@ -6,6 +6,7 @@ from docutils.transforms import Transform
__docformat__: Final = "reStructuredText"
__version__: Final[str]
@type_check_only
class _VersionInfo(NamedTuple):
major: int
minor: int
+2 -1
View File
@@ -2,10 +2,11 @@
from abc import ABCMeta, abstractmethod
from collections.abc import Mapping
from logging import Logger
from typing import Any, Protocol
from typing import Any, Protocol, type_check_only
from typing_extensions import TypeAlias
# from fonttools.ttLib.ttGlyphSet
@type_check_only
class _TTGlyph(Protocol):
def __init__(self, glyphSet: _TTGlyphSet, glyphName: str) -> None: ...
def draw(self, pen) -> None: ...
+3 -1
View File
@@ -59,7 +59,7 @@ class GraphicsStateDictRegistry(OrderedDict[Raw, Name]):
def number_to_str(number: Number) -> str: ...
def render_pdf_primitive(primitive: _Primitive) -> Raw: ...
@type_check_only
class _DeviceRGBBase(NamedTuple):
r: Number
g: Number
@@ -75,6 +75,7 @@ class DeviceRGB(_DeviceRGBBase):
def colors255(self) -> tuple[Number, Number, Number]: ...
def serialize(self) -> str: ...
@type_check_only
class _DeviceGrayBase(NamedTuple):
g: Number
a: Number | None
@@ -88,6 +89,7 @@ class DeviceGray(_DeviceGrayBase):
def colors255(self) -> tuple[Number, Number, Number]: ...
def serialize(self) -> str: ...
@type_check_only
class _DeviceCMYKBase(NamedTuple):
c: Number
m: Number
+11 -1
View File
@@ -2,7 +2,7 @@ import sys
from _typeshed import FileDescriptor, StrOrBytesPath
from collections.abc import Callable
from types import TracebackType
from typing import Any, Literal, Protocol, overload
from typing import Any, Literal, Protocol, overload, type_check_only
from typing_extensions import TypeAlias, TypeVarTuple, Unpack
_Ts = TypeVarTuple("_Ts")
@@ -19,6 +19,7 @@ _Ts = TypeVarTuple("_Ts")
# properties and methods that are available on all event loops, so these have
# been added as well, instead of completely mirroring the internal interface
@type_check_only
class _Loop(Protocol): # noqa: Y046
@property
def approx_timer_resolution(self) -> float: ...
@@ -66,6 +67,7 @@ class _Loop(Protocol): # noqa: Y046
def run_callback_threadsafe(self, func: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> _Callback: ...
def fileno(self) -> FileDescriptor | None: ...
@type_check_only
class _Watcher(Protocol):
# while IWatcher allows for kwargs the actual implementation does not...
def start(self, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ...
@@ -73,6 +75,7 @@ class _Watcher(Protocol):
def close(self) -> None: ...
# this matches Intersection[_Watcher, TimerMixin]
@type_check_only
class _TimerWatcher(_Watcher, Protocol):
# this has one specific allowed keyword argument, if it is given we don't try to check
# the passed in arguments, but if it isn't passed in, then we do.
@@ -86,6 +89,7 @@ class _TimerWatcher(_Watcher, Protocol):
def again(self, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ...
# this matches Intersection[_Watcher, IoMixin]
@type_check_only
class _IoWatcher(_Watcher, Protocol):
EVENT_MASK: int
# pass_events means the first argument of the callback needs to be an integer, but we can't
@@ -96,6 +100,7 @@ class _IoWatcher(_Watcher, Protocol):
def start(self, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ...
# this matches Intersection[_Watcher, ChildMixin]
@type_check_only
class _ChildWatcher(_Watcher, Protocol):
@property
def pid(self) -> int: ...
@@ -105,6 +110,7 @@ class _ChildWatcher(_Watcher, Protocol):
def rstatus(self) -> int: ...
# this matches Intersection[_Watcher, AsyncMixin]
@type_check_only
class _AsyncWatcher(_Watcher, Protocol):
def send(self) -> None: ...
def send_ignoring_arg(self, ignored: object, /) -> None: ...
@@ -112,11 +118,13 @@ class _AsyncWatcher(_Watcher, Protocol):
def pending(self) -> bool: ...
# all implementations return something of this shape
@type_check_only
class _StatResult(Protocol):
@property
def st_nlink(self) -> int: ...
# this matches Intersection[_Watcher, StatMixin]
@type_check_only
class _StatWatcher(_Watcher, Protocol):
@property
def path(self) -> StrOrBytesPath: ...
@@ -127,6 +135,7 @@ class _StatWatcher(_Watcher, Protocol):
@property
def interval(self) -> float: ...
@type_check_only
class _Callback(Protocol):
pending: bool
def stop(self) -> None: ...
@@ -137,6 +146,7 @@ _SockAddr: TypeAlias = _FullSockAddr | tuple[str, int]
_AddrinfoResult: TypeAlias = list[tuple[int, int, int, str, _SockAddr]] # family, type, protocol, cname, sockaddr
_NameinfoResult: TypeAlias = tuple[str, str]
@type_check_only
class _Resolver(Protocol): # noqa: Y046
def close(self) -> None: ...
def gethostbyname(self, hostname: str, family: int = 2) -> str: ...
@@ -2,7 +2,7 @@
from _typeshed import Incomplete, ReadableBuffer
from collections.abc import Iterable, Iterator, Mapping, Sequence
from typing import Any, Protocol, TypeVar, overload
from typing import Any, Protocol, TypeVar, overload, type_check_only
from typing_extensions import TypeAlias
from xml.etree.ElementTree import Element, ElementTree, QName, XMLParser, _FileRead
@@ -17,34 +17,52 @@ _T_co = TypeVar("_T_co", covariant=True)
# Usually an Element() from either lxml or xml.etree (has a 'tag' element)
# lxml.etree._Element
# xml.etree.Element
@type_check_only
class _HasTag(Protocol):
tag: str
@type_check_only
class _HasGet(Protocol[_T_co]):
def get(self, value: str, /) -> _T_co | None: ...
@type_check_only
class _HasText(Protocol):
text: str
@type_check_only
class _HasAttrib(Protocol):
attrib: Iterable[Any] # AnyOf[dict[str, str], Iterable[tuple[str, str]]]
@type_check_only
class _HasTagAndGet(_HasTag, _HasGet[_T_co], Protocol[_T_co]): ... # noqa: Y046
@type_check_only
class _HasTagAndText(_HasTag, _HasText, Protocol): ... # noqa: Y046
@type_check_only
class _HasTagAndTextAndAttrib(_HasTag, _HasText, _HasAttrib, Protocol): ... # noqa: Y046
@type_check_only
class _SupportsFindChartLines(Protocol):
def find(self, path: str, /) -> ChartLines | None: ...
@type_check_only
class _SupportsFindAndIterAndAttribAndText( # noqa: Y046
_SupportsFindChartLines, Iterable[Incomplete], _HasAttrib, _HasText, Protocol
): ...
@type_check_only
class _SupportsIterAndAttrib(Iterable[Incomplete], _HasAttrib, Protocol): ... # noqa: Y046
@type_check_only
class _SupportsIterAndAttribAndTextAndTag(Iterable[Incomplete], _HasAttrib, _HasText, _HasTag, Protocol): ... # noqa: Y046
@type_check_only
class _SupportsIterAndAttribAndTextAndGet( # noqa: Y046
Iterable[Incomplete], _HasAttrib, _HasText, _HasGet[Incomplete], Protocol
): ...
@type_check_only
class _ParentElement(Protocol[_T]):
def makeelement(self, tag: str, attrib: dict[str, str], /) -> _T: ...
def append(self, element: _T, /) -> object: ...
@@ -1 +0,0 @@
paramiko.util.SupportsClose
+1 -4
View File
@@ -3,15 +3,12 @@ from collections.abc import Iterable
from hashlib import _Hash
from logging import Logger, LogRecord
from types import TracebackType
from typing import IO, AnyStr, Protocol
from typing import IO, AnyStr
from typing_extensions import Self
from paramiko.config import SSHConfig, SSHConfigDict
from paramiko.hostkeys import HostKeys
class SupportsClose(Protocol):
def close(self) -> None: ...
def inflate_long(s: bytes | bytearray, always_positive: bool = False) -> int: ...
def deflate_long(n: int, add_sign_padding: bool = True) -> bytes: ...
def format_binary(data: bytes | bytearray, prefix: str = "") -> list[str]: ...
+2 -1
View File
@@ -1,8 +1,9 @@
from _typeshed import Incomplete
from types import ModuleType
from typing import Protocol
from typing import Protocol, type_check_only
# Protocol for flask.Flask class
@type_check_only
class _Flask(Protocol):
def before_request(self, f): ...
def after_request(self, f): ...
@@ -3,8 +3,9 @@
# Anything not referenced in the PyInstaller stubs doesn't need to be added here.
from types import CodeType
from typing import Protocol
from typing import Protocol, type_check_only
@type_check_only
class _SupportsGraphident(Protocol):
graphident: str
+2 -1
View File
@@ -1,6 +1,6 @@
# Type aliases used in this stub package
from _typeshed import SupportsWrite
from typing import Any, Protocol
from typing import Any, Protocol, type_check_only
from typing_extensions import TypeAlias
Box: TypeAlias = tuple[tuple[int, int], tuple[int, int]]
@@ -11,5 +11,6 @@ Ink: TypeAlias = tuple[int, int, int] | tuple[int, int, int, int]
ErrorCorrect: TypeAlias = int
MaskPattern: TypeAlias = int
@type_check_only
class Writeable(SupportsWrite[bytes], Protocol):
def seek(self, offset: int, /) -> Any: ...
+3 -1
View File
@@ -2,7 +2,7 @@
# Everything in this module is private for stubs. There is no runtime equivalent.
from collections.abc import Iterable, Mapping, Sequence
from typing import Any, Protocol, TypeVar
from typing import Any, Protocol, TypeVar, type_check_only
from typing_extensions import TypeAlias
import numpy as np
@@ -20,9 +20,11 @@ RaggedTensorLike: TypeAlias = tf.Tensor | tf.RaggedTensor
# _RaggedTensorLikeT = TypeVar("_RaggedTensorLikeT", tf.Tensor, tf.RaggedTensor)
Gradients: TypeAlias = tf.Tensor | tf.IndexedSlices
@type_check_only
class KerasSerializable1(Protocol):
def get_config(self) -> dict[str, Any]: ...
@type_check_only
class KerasSerializable2(Protocol):
__name__: str
@@ -1,8 +1,9 @@
import typing_extensions
from typing import TypedDict
from typing import TypedDict, type_check_only
from tensorflow.config import PhysicalDevice
@type_check_only
class _MemoryInfo(TypedDict):
current: int
peak: int