diff --git a/stubs/RPi.GPIO/RPi/GPIO/__init__.pyi b/stubs/RPi.GPIO/RPi/GPIO/__init__.pyi index 861eb9a170da..f35db8b59f0c 100644 --- a/stubs/RPi.GPIO/RPi/GPIO/__init__.pyi +++ b/stubs/RPi.GPIO/RPi/GPIO/__init__.pyi @@ -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 diff --git a/stubs/WebOb/webob/_types.pyi b/stubs/WebOb/webob/_types.pyi index 08fdc54b3dd6..90cd26e1f24f 100644 --- a/stubs/WebOb/webob/_types.pyi +++ b/stubs/WebOb/webob/_types.pyi @@ -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] ): diff --git a/stubs/docker/docker/types/services.pyi b/stubs/docker/docker/types/services.pyi index 54baedb5daf1..c11eb292cf6f 100644 --- a/stubs/docker/docker/types/services.pyi +++ b/stubs/docker/docker/types/services.pyi @@ -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 diff --git a/stubs/docutils/docutils/__init__.pyi b/stubs/docutils/docutils/__init__.pyi index 6b97f04044aa..9845ec945daa 100644 --- a/stubs/docutils/docutils/__init__.pyi +++ b/stubs/docutils/docutils/__init__.pyi @@ -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 diff --git a/stubs/fpdf2/fpdf/_fonttools_shims.pyi b/stubs/fpdf2/fpdf/_fonttools_shims.pyi index f68d651014d6..499c8861ce83 100644 --- a/stubs/fpdf2/fpdf/_fonttools_shims.pyi +++ b/stubs/fpdf2/fpdf/_fonttools_shims.pyi @@ -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: ... diff --git a/stubs/fpdf2/fpdf/drawing.pyi b/stubs/fpdf2/fpdf/drawing.pyi index c393f1f7eaa7..94b23cdd371b 100644 --- a/stubs/fpdf2/fpdf/drawing.pyi +++ b/stubs/fpdf2/fpdf/drawing.pyi @@ -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 diff --git a/stubs/gevent/gevent/_types.pyi b/stubs/gevent/gevent/_types.pyi index 16db1f4d497f..ea0263a1b56c 100644 --- a/stubs/gevent/gevent/_types.pyi +++ b/stubs/gevent/gevent/_types.pyi @@ -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: ... diff --git a/stubs/openpyxl/openpyxl/xml/_functions_overloads.pyi b/stubs/openpyxl/openpyxl/xml/_functions_overloads.pyi index cbdac51f363c..6dfbd17513c1 100644 --- a/stubs/openpyxl/openpyxl/xml/_functions_overloads.pyi +++ b/stubs/openpyxl/openpyxl/xml/_functions_overloads.pyi @@ -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: ... diff --git a/stubs/paramiko/@tests/stubtest_allowlist.txt b/stubs/paramiko/@tests/stubtest_allowlist.txt deleted file mode 100644 index fdabe6f8a4b8..000000000000 --- a/stubs/paramiko/@tests/stubtest_allowlist.txt +++ /dev/null @@ -1 +0,0 @@ -paramiko.util.SupportsClose diff --git a/stubs/paramiko/paramiko/util.pyi b/stubs/paramiko/paramiko/util.pyi index f45123625b4e..be94a8a23053 100644 --- a/stubs/paramiko/paramiko/util.pyi +++ b/stubs/paramiko/paramiko/util.pyi @@ -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]: ... diff --git a/stubs/pony/pony/flask/__init__.pyi b/stubs/pony/pony/flask/__init__.pyi index ce220f1b7d60..080bcc2272aa 100644 --- a/stubs/pony/pony/flask/__init__.pyi +++ b/stubs/pony/pony/flask/__init__.pyi @@ -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): ... diff --git a/stubs/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.pyi b/stubs/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.pyi index 83df57a0ca30..2783e2249008 100644 --- a/stubs/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.pyi +++ b/stubs/pyinstaller/PyInstaller/lib/modulegraph/modulegraph.pyi @@ -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 diff --git a/stubs/qrcode/qrcode/_types.pyi b/stubs/qrcode/qrcode/_types.pyi index 2fb145fc4fc0..8baf3f940f1d 100644 --- a/stubs/qrcode/qrcode/_types.pyi +++ b/stubs/qrcode/qrcode/_types.pyi @@ -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: ... diff --git a/stubs/tensorflow/tensorflow/_aliases.pyi b/stubs/tensorflow/tensorflow/_aliases.pyi index 6bc6918a6b21..80e72ba87122 100644 --- a/stubs/tensorflow/tensorflow/_aliases.pyi +++ b/stubs/tensorflow/tensorflow/_aliases.pyi @@ -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 diff --git a/stubs/tensorflow/tensorflow/config/experimental.pyi b/stubs/tensorflow/tensorflow/config/experimental.pyi index 1cb74feba722..aa9dcc53ed2e 100644 --- a/stubs/tensorflow/tensorflow/config/experimental.pyi +++ b/stubs/tensorflow/tensorflow/config/experimental.pyi @@ -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