Skip to content

Commit 282b1a8

Browse files
authored
Add @type_check_only to stub-only private classes in various third-party stubs (#15535)
1 parent 222da06 commit 282b1a8

File tree

15 files changed

+56
-18
lines changed

15 files changed

+56
-18
lines changed

stubs/RPi.GPIO/RPi/GPIO/__init__.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from collections.abc import Callable
2-
from typing import Final, Literal, TypedDict
2+
from typing import Final, Literal, TypedDict, type_check_only
33
from typing_extensions import TypeAlias
44

5+
@type_check_only
56
class _RPi_Info(TypedDict):
67
P1_REVISION: int
78
REVISION: str

stubs/WebOb/webob/_types.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
from typing import Protocol, TypeVar, overload
1+
from typing import Protocol, TypeVar, overload, type_check_only
22
from typing_extensions import TypeAlias
33

44
_T = TypeVar("_T")
55
_GetterReturnType_co = TypeVar("_GetterReturnType_co", covariant=True)
66
_SetterValueType_contra = TypeVar("_SetterValueType_contra", contravariant=True)
77

8+
@type_check_only
89
class AsymmetricProperty(Protocol[_GetterReturnType_co, _SetterValueType_contra]):
910
@overload
1011
def __get__(self, obj: None, type: type[object] | None = ..., /) -> property: ...
1112
@overload
1213
def __get__(self, obj: object, type: type[object] | None = ..., /) -> _GetterReturnType_co: ...
1314
def __set__(self, obj: object, value: _SetterValueType_contra, /) -> None: ...
1415

16+
@type_check_only
1517
class AsymmetricPropertyWithDelete(
1618
AsymmetricProperty[_GetterReturnType_co, _SetterValueType_contra], Protocol[_GetterReturnType_co, _SetterValueType_contra]
1719
):

stubs/docker/docker/types/services.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from _typeshed import Incomplete
22
from collections.abc import Iterable, Mapping
3-
from typing import Final, Literal, TypedDict, TypeVar, overload
3+
from typing import Final, Literal, TypedDict, TypeVar, overload, type_check_only
44

55
from .healthcheck import Healthcheck
66

@@ -75,6 +75,7 @@ class Mount(dict[str, Incomplete]):
7575
@classmethod
7676
def parse_mount_string(cls, string: str) -> Mount: ...
7777

78+
@type_check_only
7879
class _ResourceDict(TypedDict):
7980
Kind: str
8081
Value: int

stubs/docutils/docutils/__init__.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
from typing import Any, ClassVar, Final, NamedTuple
1+
from typing import Any, ClassVar, Final, NamedTuple, type_check_only
22
from typing_extensions import Self
33

44
from docutils.transforms import Transform
55

66
__docformat__: Final = "reStructuredText"
77
__version__: Final[str]
88

9+
@type_check_only
910
class _VersionInfo(NamedTuple):
1011
major: int
1112
minor: int

stubs/fpdf2/fpdf/_fonttools_shims.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
from abc import ABCMeta, abstractmethod
33
from collections.abc import Mapping
44
from logging import Logger
5-
from typing import Any, Protocol
5+
from typing import Any, Protocol, type_check_only
66
from typing_extensions import TypeAlias
77

88
# from fonttools.ttLib.ttGlyphSet
9+
@type_check_only
910
class _TTGlyph(Protocol):
1011
def __init__(self, glyphSet: _TTGlyphSet, glyphName: str) -> None: ...
1112
def draw(self, pen) -> None: ...

stubs/fpdf2/fpdf/drawing.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class GraphicsStateDictRegistry(OrderedDict[Raw, Name]):
5959

6060
def number_to_str(number: Number) -> str: ...
6161
def render_pdf_primitive(primitive: _Primitive) -> Raw: ...
62-
62+
@type_check_only
6363
class _DeviceRGBBase(NamedTuple):
6464
r: Number
6565
g: Number
@@ -75,6 +75,7 @@ class DeviceRGB(_DeviceRGBBase):
7575
def colors255(self) -> tuple[Number, Number, Number]: ...
7676
def serialize(self) -> str: ...
7777

78+
@type_check_only
7879
class _DeviceGrayBase(NamedTuple):
7980
g: Number
8081
a: Number | None
@@ -88,6 +89,7 @@ class DeviceGray(_DeviceGrayBase):
8889
def colors255(self) -> tuple[Number, Number, Number]: ...
8990
def serialize(self) -> str: ...
9091

92+
@type_check_only
9193
class _DeviceCMYKBase(NamedTuple):
9294
c: Number
9395
m: Number

stubs/gevent/gevent/_types.pyi

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import sys
22
from _typeshed import FileDescriptor, StrOrBytesPath
33
from collections.abc import Callable
44
from types import TracebackType
5-
from typing import Any, Literal, Protocol, overload
5+
from typing import Any, Literal, Protocol, overload, type_check_only
66
from typing_extensions import TypeAlias, TypeVarTuple, Unpack
77

88
_Ts = TypeVarTuple("_Ts")
@@ -19,6 +19,7 @@ _Ts = TypeVarTuple("_Ts")
1919
# properties and methods that are available on all event loops, so these have
2020
# been added as well, instead of completely mirroring the internal interface
2121

22+
@type_check_only
2223
class _Loop(Protocol): # noqa: Y046
2324
@property
2425
def approx_timer_resolution(self) -> float: ...
@@ -66,13 +67,15 @@ class _Loop(Protocol): # noqa: Y046
6667
def run_callback_threadsafe(self, func: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> _Callback: ...
6768
def fileno(self) -> FileDescriptor | None: ...
6869

70+
@type_check_only
6971
class _Watcher(Protocol):
7072
# while IWatcher allows for kwargs the actual implementation does not...
7173
def start(self, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ...
7274
def stop(self) -> None: ...
7375
def close(self) -> None: ...
7476

7577
# this matches Intersection[_Watcher, TimerMixin]
78+
@type_check_only
7679
class _TimerWatcher(_Watcher, Protocol):
7780
# this has one specific allowed keyword argument, if it is given we don't try to check
7881
# the passed in arguments, but if it isn't passed in, then we do.
@@ -86,6 +89,7 @@ class _TimerWatcher(_Watcher, Protocol):
8689
def again(self, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ...
8790

8891
# this matches Intersection[_Watcher, IoMixin]
92+
@type_check_only
8993
class _IoWatcher(_Watcher, Protocol):
9094
EVENT_MASK: int
9195
# 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):
96100
def start(self, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ...
97101

98102
# this matches Intersection[_Watcher, ChildMixin]
103+
@type_check_only
99104
class _ChildWatcher(_Watcher, Protocol):
100105
@property
101106
def pid(self) -> int: ...
@@ -105,18 +110,21 @@ class _ChildWatcher(_Watcher, Protocol):
105110
def rstatus(self) -> int: ...
106111

107112
# this matches Intersection[_Watcher, AsyncMixin]
113+
@type_check_only
108114
class _AsyncWatcher(_Watcher, Protocol):
109115
def send(self) -> None: ...
110116
def send_ignoring_arg(self, ignored: object, /) -> None: ...
111117
@property
112118
def pending(self) -> bool: ...
113119

114120
# all implementations return something of this shape
121+
@type_check_only
115122
class _StatResult(Protocol):
116123
@property
117124
def st_nlink(self) -> int: ...
118125

119126
# this matches Intersection[_Watcher, StatMixin]
127+
@type_check_only
120128
class _StatWatcher(_Watcher, Protocol):
121129
@property
122130
def path(self) -> StrOrBytesPath: ...
@@ -127,6 +135,7 @@ class _StatWatcher(_Watcher, Protocol):
127135
@property
128136
def interval(self) -> float: ...
129137

138+
@type_check_only
130139
class _Callback(Protocol):
131140
pending: bool
132141
def stop(self) -> None: ...
@@ -137,6 +146,7 @@ _SockAddr: TypeAlias = _FullSockAddr | tuple[str, int]
137146
_AddrinfoResult: TypeAlias = list[tuple[int, int, int, str, _SockAddr]] # family, type, protocol, cname, sockaddr
138147
_NameinfoResult: TypeAlias = tuple[str, str]
139148

149+
@type_check_only
140150
class _Resolver(Protocol): # noqa: Y046
141151
def close(self) -> None: ...
142152
def gethostbyname(self, hostname: str, family: int = 2) -> str: ...

stubs/openpyxl/openpyxl/xml/_functions_overloads.pyi

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from _typeshed import Incomplete, ReadableBuffer
44
from collections.abc import Iterable, Iterator, Mapping, Sequence
5-
from typing import Any, Protocol, TypeVar, overload
5+
from typing import Any, Protocol, TypeVar, overload, type_check_only
66
from typing_extensions import TypeAlias
77
from xml.etree.ElementTree import Element, ElementTree, QName, XMLParser, _FileRead
88

@@ -17,34 +17,52 @@ _T_co = TypeVar("_T_co", covariant=True)
1717
# Usually an Element() from either lxml or xml.etree (has a 'tag' element)
1818
# lxml.etree._Element
1919
# xml.etree.Element
20+
@type_check_only
2021
class _HasTag(Protocol):
2122
tag: str
2223

24+
@type_check_only
2325
class _HasGet(Protocol[_T_co]):
2426
def get(self, value: str, /) -> _T_co | None: ...
2527

28+
@type_check_only
2629
class _HasText(Protocol):
2730
text: str
2831

32+
@type_check_only
2933
class _HasAttrib(Protocol):
3034
attrib: Iterable[Any] # AnyOf[dict[str, str], Iterable[tuple[str, str]]]
3135

36+
@type_check_only
3237
class _HasTagAndGet(_HasTag, _HasGet[_T_co], Protocol[_T_co]): ... # noqa: Y046
38+
39+
@type_check_only
3340
class _HasTagAndText(_HasTag, _HasText, Protocol): ... # noqa: Y046
41+
42+
@type_check_only
3443
class _HasTagAndTextAndAttrib(_HasTag, _HasText, _HasAttrib, Protocol): ... # noqa: Y046
3544

45+
@type_check_only
3646
class _SupportsFindChartLines(Protocol):
3747
def find(self, path: str, /) -> ChartLines | None: ...
3848

49+
@type_check_only
3950
class _SupportsFindAndIterAndAttribAndText( # noqa: Y046
4051
_SupportsFindChartLines, Iterable[Incomplete], _HasAttrib, _HasText, Protocol
4152
): ...
53+
54+
@type_check_only
4255
class _SupportsIterAndAttrib(Iterable[Incomplete], _HasAttrib, Protocol): ... # noqa: Y046
56+
57+
@type_check_only
4358
class _SupportsIterAndAttribAndTextAndTag(Iterable[Incomplete], _HasAttrib, _HasText, _HasTag, Protocol): ... # noqa: Y046
59+
60+
@type_check_only
4461
class _SupportsIterAndAttribAndTextAndGet( # noqa: Y046
4562
Iterable[Incomplete], _HasAttrib, _HasText, _HasGet[Incomplete], Protocol
4663
): ...
4764

65+
@type_check_only
4866
class _ParentElement(Protocol[_T]):
4967
def makeelement(self, tag: str, attrib: dict[str, str], /) -> _T: ...
5068
def append(self, element: _T, /) -> object: ...

stubs/paramiko/@tests/stubtest_allowlist.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

stubs/paramiko/paramiko/util.pyi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ from collections.abc import Iterable
33
from hashlib import _Hash
44
from logging import Logger, LogRecord
55
from types import TracebackType
6-
from typing import IO, AnyStr, Protocol
6+
from typing import IO, AnyStr
77
from typing_extensions import Self
88

99
from paramiko.config import SSHConfig, SSHConfigDict
1010
from paramiko.hostkeys import HostKeys
1111

12-
class SupportsClose(Protocol):
13-
def close(self) -> None: ...
14-
1512
def inflate_long(s: bytes | bytearray, always_positive: bool = False) -> int: ...
1613
def deflate_long(n: int, add_sign_padding: bool = True) -> bytes: ...
1714
def format_binary(data: bytes | bytearray, prefix: str = "") -> list[str]: ...

0 commit comments

Comments
 (0)