Skip to content

Commit 47dbbd6

Browse files
Add @disjoint_base decorator to the third-party stubs (#14716)
1 parent 0d100b9 commit 47dbbd6

File tree

27 files changed

+110
-24
lines changed

27 files changed

+110
-24
lines changed

stubs/PyYAML/yaml/_yaml.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from _typeshed import Incomplete, SupportsRead
22
from collections.abc import Mapping, Sequence
33
from typing import IO, Any
4+
from typing_extensions import disjoint_base
45

56
from .events import Event
67
from .nodes import Node
78
from .tokens import Token
89

910
def get_version_string() -> str: ...
1011
def get_version() -> tuple[int, int, int]: ...
11-
12+
@disjoint_base
1213
class Mark:
1314
name: Any
1415
index: int
@@ -19,6 +20,7 @@ class Mark:
1920
def __init__(self, name, index: int, line: int, column: int, buffer, pointer) -> None: ...
2021
def get_snippet(self): ...
2122

23+
@disjoint_base
2224
class CParser:
2325
def __init__(self, stream: str | bytes | SupportsRead[str | bytes]) -> None: ...
2426
def dispose(self) -> None: ...
@@ -34,6 +36,7 @@ class CParser:
3436
def raw_parse(self) -> int: ...
3537
def raw_scan(self) -> int: ...
3638

39+
@disjoint_base
3740
class CEmitter:
3841
def __init__(
3942
self,

stubs/cffi/_cffi_backend.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import types
33
from _typeshed import Incomplete, ReadableBuffer, WriteableBuffer
44
from collections.abc import Callable, Hashable
55
from typing import Any, ClassVar, Literal, Protocol, SupportsIndex, TypeVar, final, overload, type_check_only
6-
from typing_extensions import Self, TypeAlias
6+
from typing_extensions import Self, TypeAlias, disjoint_base
77

88
_T = TypeVar("_T")
99

@@ -111,6 +111,7 @@ class buffer:
111111
_tmp_CType = CType
112112
_tmp_buffer = buffer
113113

114+
@disjoint_base
114115
class FFI:
115116
CData: TypeAlias = _CDataBase
116117
CType: TypeAlias = _tmp_CType

stubs/gdb/gdb/__init__.pyi

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import threading
77
from collections.abc import Callable, Iterator, Mapping, Sequence
88
from contextlib import AbstractContextManager
99
from typing import Any, Final, Generic, Literal, Protocol, TypedDict, TypeVar, final, overload, type_check_only
10-
from typing_extensions import TypeAlias, deprecated
10+
from typing_extensions import TypeAlias, deprecated, disjoint_base
1111

1212
import gdb.FrameDecorator
1313
import gdb.types
@@ -74,6 +74,7 @@ class GdbError(Exception): ...
7474
_ValueOrNative: TypeAlias = bool | int | float | str | Value | LazyString
7575
_ValueOrInt: TypeAlias = Value | int
7676

77+
@disjoint_base
7778
class Value:
7879
address: Value
7980
is_optimized_out: bool
@@ -406,6 +407,7 @@ class RecordFunctionSegment:
406407

407408
# CLI Commands
408409

410+
@disjoint_base
409411
class Command:
410412
def __init__(self, name: str, command_class: int, completer_class: int = ..., prefix: bool = ...) -> None: ...
411413
def dont_repeat(self) -> None: ...
@@ -437,6 +439,7 @@ COMPLETE_EXPRESSION: int
437439

438440
# GDB/MI Commands
439441

442+
@disjoint_base
440443
class MICommand:
441444
name: str
442445
installed: bool
@@ -446,6 +449,7 @@ class MICommand:
446449

447450
# Parameters
448451

452+
@disjoint_base
449453
class Parameter:
450454
set_doc: str
451455
show_doc: str
@@ -682,6 +686,7 @@ class LineTable:
682686

683687
# Breakpoints
684688

689+
@disjoint_base
685690
class Breakpoint:
686691
# The where="spec" form of __init__(). See py-breakpoints.c:bppy_init():keywords for the positional order.
687692
@overload
@@ -854,6 +859,7 @@ WP_ACCESS: int
854859

855860
# Finish Breakpoints
856861

862+
@disjoint_base
857863
class FinishBreakpoint(Breakpoint):
858864
return_value: Value | None
859865

@@ -907,6 +913,7 @@ class RegisterGroupsIterator(Iterator[RegisterGroup]):
907913

908914
# Connections
909915

916+
@disjoint_base
910917
class TargetConnection:
911918
def is_valid(self) -> bool: ...
912919

@@ -941,6 +948,7 @@ class _Window(Protocol):
941948
def click(self, x: int, y: int, button: int) -> None: ...
942949

943950
# Events
951+
@disjoint_base
944952
class Event: ...
945953

946954
class ThreadEvent(Event):

stubs/gdb/gdb/disassembler.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections.abc import Sequence
22
from typing import Final, final
3+
from typing_extensions import disjoint_base
34

45
import gdb
56
from gdb import Architecture, Progspace
@@ -8,6 +9,7 @@ class Disassembler:
89
def __init__(self, name: str) -> None: ...
910
def __call__(self, info): ...
1011

12+
@disjoint_base
1113
class DisassembleInfo:
1214
address: int
1315
architecture: Architecture

stubs/gevent/@tests/stubtest_allowlist.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ gevent.socket.SocketType.makefile
6464
gevent.socket.SocketType.sendfile
6565
gevent.socket.SocketType.set_inheritable
6666

67+
# Pretends to re-export a type marked @disjoint_base in the stubs, but runtime
68+
# defines __slots__
69+
gevent.socket.SocketType$
70+
6771
# zope.interface related attributes we can ignore
6872
gevent.[\w\.]+\.__implemented__
6973
gevent.[\w\.]+\.__providedBy__

stubs/gevent/gevent/_greenlet_primitives.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from abc import abstractmethod
22
from typing import Any, NoReturn
3+
from typing_extensions import disjoint_base
34

45
from gevent._types import _Loop
56
from greenlet import greenlet
67

78
class TrackedRawGreenlet(greenlet): ...
89

10+
@disjoint_base
911
class SwitchOutGreenletWithLoop(TrackedRawGreenlet):
1012
@property
1113
@abstractmethod

stubs/gevent/gevent/_hub_primitives.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from _typeshed import FileDescriptor
22
from collections.abc import Callable, Collection, Iterable
33
from types import TracebackType
44
from typing import Any, Generic, Protocol, TypeVar, overload, type_check_only
5-
from typing_extensions import Self, TypeVarTuple, Unpack
5+
from typing_extensions import Self, TypeVarTuple, Unpack, disjoint_base
66

77
from gevent._greenlet_primitives import SwitchOutGreenletWithLoop
88
from gevent._types import _Loop, _Watcher
@@ -32,6 +32,7 @@ class WaitOperationsGreenlet(SwitchOutGreenletWithLoop):
3232
) -> None: ...
3333
def cancel_wait(self, watcher: _Watcher, error: type[BaseException] | BaseException, close_watcher: bool = False) -> None: ...
3434

35+
@disjoint_base
3536
class _WaitIterator(Generic[_T]):
3637
def __init__(self, objects: Collection[_T], hub: Hub, timeout: float, count: None | int) -> None: ...
3738
def __enter__(self) -> Self: ...

stubs/gevent/gevent/_imap.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections.abc import Callable, Iterable
22
from typing import Any, TypeVar
3-
from typing_extensions import ParamSpec, Self
3+
from typing_extensions import ParamSpec, Self, disjoint_base
44

55
from gevent.greenlet import Greenlet
66
from gevent.queue import UnboundQueue
@@ -12,6 +12,7 @@ _P = ParamSpec("_P")
1212
# returned by some public API functions, we don't bother adding a whole bunch of overloads to handle
1313
# the case of 1-n Iterables being passed in and just go for the fully unsafe signature
1414
# we do the crazy overloads instead in the functions that create these objects
15+
@disjoint_base
1516
class IMapUnordered(Greenlet[_P, _T]):
1617
finished: bool
1718
# it may contain an undocumented Failure object
@@ -20,6 +21,7 @@ class IMapUnordered(Greenlet[_P, _T]):
2021
def __iter__(self) -> Self: ...
2122
def __next__(self) -> _T: ...
2223

24+
@disjoint_base
2325
class IMap(IMapUnordered[_P, _T]):
2426
index: int
2527

stubs/gevent/gevent/greenlet.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import weakref
22
from collections.abc import Callable, Iterable, Sequence
33
from types import FrameType, TracebackType
44
from typing import Any, ClassVar, Generic, TypeVar, overload
5-
from typing_extensions import ParamSpec, Self
5+
from typing_extensions import ParamSpec, Self, disjoint_base
66

77
import greenlet
88
from gevent._types import _Loop
@@ -12,6 +12,7 @@ _T = TypeVar("_T")
1212
_G = TypeVar("_G", bound=greenlet.greenlet)
1313
_P = ParamSpec("_P")
1414

15+
@disjoint_base
1516
class Greenlet(greenlet.greenlet, Generic[_P, _T]):
1617
# we can't use _P.args/_P.kwargs here because pyright will complain
1718
# mypy doesn't seem to mind though

stubs/gevent/gevent/libev/corecext.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from _typeshed import FileDescriptor
33
from collections.abc import Callable, Sequence
44
from types import TracebackType
55
from typing import Any
6-
from typing_extensions import ParamSpec
6+
from typing_extensions import ParamSpec, disjoint_base
77

88
from gevent._ffi.loop import _ErrorHandler
99
from gevent._types import _Callback
@@ -20,7 +20,7 @@ if sys.platform != "win32":
2020
def recommended_backends() -> list[str | int]: ...
2121
def supported_backends() -> list[str | int]: ...
2222
def time() -> float: ...
23-
23+
@disjoint_base
2424
class loop:
2525
starting_timer_may_update_loop_time: bool
2626
error_handler: _ErrorHandler

0 commit comments

Comments
 (0)