Skip to content

Commit 5461d37

Browse files
authored
de-duplicate _dummy_threading (#13063)
While technically it's an independent implementation, the classes all call themselves `threading.*` and have the same interfaces. Except for local, which is from _threading_local instead.
1 parent 4890153 commit 5461d37

File tree

2 files changed

+19
-133
lines changed

2 files changed

+19
-133
lines changed

stdlib/@tests/stubtest_allowlists/py38.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,18 @@
44

55
_dummy_threading.Condition.acquire
66
_dummy_threading.Condition.release
7-
_dummy_threading.Event.isSet
87
_dummy_threading.ExceptHookArgs
98
_dummy_threading.Lock
109
_dummy_threading.RLock
1110
_dummy_threading.Thread.native_id
12-
_dummy_threading._DummyThread.__init__
13-
_dummy_threading._RLock.__enter__
14-
_dummy_threading.local.__new__
1511
asyncio.WriteTransport.get_write_buffer_limits # Documented. Exists in subclasses, but not in WriteTransport itself
1612
asyncio.locks._ContextManagerMixin.__enter__ # Always raises; deliberately omitted from the stub
1713
asyncio.locks._ContextManagerMixin.__exit__ # Always raises; deliberately omitted from the stub
1814
asyncio.transports.WriteTransport.get_write_buffer_limits # Documented. Exists in subclasses, but not in WriteTransport itself
1915
builtins.float.__set_format__ # Internal method for CPython test suite
2016
dummy_threading.Condition.acquire
2117
dummy_threading.Condition.release
22-
dummy_threading.Event.isSet
2318
dummy_threading.Thread.native_id
24-
dummy_threading.local.__new__
2519
typing.NamedTuple.__new__
2620
typing.NamedTuple._asdict
2721
typing.NamedTuple._make

stdlib/_dummy_threading.pyi

Lines changed: 19 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
import sys
2-
from _thread import _excepthook, _ExceptHookArgs
1+
from _threading_local import local as local
32
from _typeshed import ProfileFunction, TraceFunction
4-
from collections.abc import Callable, Iterable, Mapping
5-
from types import TracebackType
6-
from typing import Any, TypeVar
7-
8-
_T = TypeVar("_T")
3+
from threading import (
4+
TIMEOUT_MAX as TIMEOUT_MAX,
5+
Barrier as Barrier,
6+
BoundedSemaphore as BoundedSemaphore,
7+
BrokenBarrierError as BrokenBarrierError,
8+
Condition as Condition,
9+
Event as Event,
10+
ExceptHookArgs as ExceptHookArgs,
11+
Lock as Lock,
12+
RLock as RLock,
13+
Semaphore as Semaphore,
14+
Thread as Thread,
15+
ThreadError as ThreadError,
16+
Timer as Timer,
17+
_DummyThread as _DummyThread,
18+
_RLock as _RLock,
19+
excepthook as excepthook,
20+
)
921

1022
__all__ = [
1123
"get_ident",
@@ -42,123 +54,3 @@ def main_thread() -> Thread: ...
4254
def settrace(func: TraceFunction) -> None: ...
4355
def setprofile(func: ProfileFunction | None) -> None: ...
4456
def stack_size(size: int | None = None) -> int: ...
45-
46-
TIMEOUT_MAX: float
47-
48-
class ThreadError(Exception): ...
49-
50-
class local:
51-
def __getattribute__(self, name: str) -> Any: ...
52-
def __setattr__(self, name: str, value: Any) -> None: ...
53-
def __delattr__(self, name: str) -> None: ...
54-
55-
class Thread:
56-
name: str
57-
daemon: bool
58-
@property
59-
def ident(self) -> int | None: ...
60-
def __init__(
61-
self,
62-
group: None = None,
63-
target: Callable[..., object] | None = None,
64-
name: str | None = None,
65-
args: Iterable[Any] = (),
66-
kwargs: Mapping[str, Any] | None = None,
67-
*,
68-
daemon: bool | None = None,
69-
) -> None: ...
70-
def start(self) -> None: ...
71-
def run(self) -> None: ...
72-
def join(self, timeout: float | None = None) -> None: ...
73-
def getName(self) -> str: ...
74-
def setName(self, name: str) -> None: ...
75-
@property
76-
def native_id(self) -> int | None: ... # only available on some platforms
77-
def is_alive(self) -> bool: ...
78-
if sys.version_info < (3, 9):
79-
def isAlive(self) -> bool: ...
80-
81-
def isDaemon(self) -> bool: ...
82-
def setDaemon(self, daemonic: bool) -> None: ...
83-
84-
class _DummyThread(Thread): ...
85-
86-
class Lock:
87-
def __enter__(self) -> bool: ...
88-
def __exit__(
89-
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
90-
) -> bool | None: ...
91-
def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ...
92-
def release(self) -> None: ...
93-
def locked(self) -> bool: ...
94-
95-
class _RLock:
96-
def __enter__(self) -> bool: ...
97-
def __exit__(
98-
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
99-
) -> bool | None: ...
100-
def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: ...
101-
def release(self) -> None: ...
102-
103-
RLock = _RLock
104-
105-
class Condition:
106-
def __init__(self, lock: Lock | _RLock | None = None) -> None: ...
107-
def __enter__(self) -> bool: ...
108-
def __exit__(
109-
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
110-
) -> bool | None: ...
111-
def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ...
112-
def release(self) -> None: ...
113-
def wait(self, timeout: float | None = None) -> bool: ...
114-
def wait_for(self, predicate: Callable[[], _T], timeout: float | None = None) -> _T: ...
115-
def notify(self, n: int = 1) -> None: ...
116-
def notify_all(self) -> None: ...
117-
def notifyAll(self) -> None: ...
118-
119-
class Semaphore:
120-
def __init__(self, value: int = 1) -> None: ...
121-
def __exit__(
122-
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
123-
) -> bool | None: ...
124-
def acquire(self, blocking: bool = True, timeout: float | None = None) -> bool: ...
125-
def __enter__(self, blocking: bool = True, timeout: float | None = None) -> bool: ...
126-
if sys.version_info >= (3, 9):
127-
def release(self, n: int = ...) -> None: ...
128-
else:
129-
def release(self) -> None: ...
130-
131-
class BoundedSemaphore(Semaphore): ...
132-
133-
class Event:
134-
def is_set(self) -> bool: ...
135-
def set(self) -> None: ...
136-
def clear(self) -> None: ...
137-
def wait(self, timeout: float | None = None) -> bool: ...
138-
139-
excepthook = _excepthook
140-
ExceptHookArgs = _ExceptHookArgs
141-
142-
class Timer(Thread):
143-
def __init__(
144-
self,
145-
interval: float,
146-
function: Callable[..., object],
147-
args: Iterable[Any] | None = None,
148-
kwargs: Mapping[str, Any] | None = None,
149-
) -> None: ...
150-
def cancel(self) -> None: ...
151-
152-
class Barrier:
153-
@property
154-
def parties(self) -> int: ...
155-
@property
156-
def n_waiting(self) -> int: ...
157-
@property
158-
def broken(self) -> bool: ...
159-
def __init__(self, parties: int, action: Callable[[], None] | None = None, timeout: float | None = None) -> None: ...
160-
def wait(self, timeout: float | None = None) -> int: ...
161-
def reset(self) -> None: ...
162-
def abort(self) -> None: ...
163-
164-
class BrokenBarrierError(RuntimeError): ...

0 commit comments

Comments
 (0)