diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index e87ba193c..7bfa46508 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -43,18 +43,6 @@ ipaddress._BaseAddress.is_unspecified ipaddress._BaseAddress.max_prefixlen ipaddress._BaseAddress.packed ipaddress._BaseNetwork.max_prefixlen -multiprocessing.JoinableQueue -multiprocessing.Queue -multiprocessing.SimpleQueue -multiprocessing.queues.JoinableQueue.__init__ -multiprocessing.queues.Queue.__init__ -multiprocessing.queues.SimpleQueue.__init__ -multiprocessing.synchronize.Barrier.__init__ -multiprocessing.synchronize.Condition.acquire -multiprocessing.synchronize.Condition.release -multiprocessing.synchronize.SemLock.__init__ -multiprocessing.synchronize.SemLock.acquire -multiprocessing.synchronize.SemLock.release numbers.Number.__hash__ # typeshed marks this as abstract but code just sets this as None optparse.Values.__getattr__ # Some attributes are set in __init__ using setattr pickle.Pickler.reducer_override # implemented in C pickler @@ -410,6 +398,13 @@ inspect.Signature.__init__ inspect.Parameter.empty # set as private marker _empty inspect.Signature.empty # set as private marker _empty +# At runtime, these are functions from multiprocessing.context._default_context. +# Typeshed makes them classes instead, which matches CPython documentation. +# This has been heavily discussed, see #4266 for the primary issue about it. +multiprocessing.JoinableQueue +multiprocessing.Queue +multiprocessing.SimpleQueue + # These multiprocessing proxy methods have *args, **kwargs signatures at runtime, # But have more precise (accurate) signatures in the stub multiprocessing.managers.BaseListProxy.__imul__ @@ -432,6 +427,22 @@ multiprocessing.reduction.AbstractReducer.ForkingPickler # Non-private parameter on __del__ multiprocessing.pool.Pool.__del__ +# These are because the ctx argument has a default value in the stubs but not +# at runtime. This is a compromise between the runtime signatures of (for example) +# multiprocessing.Queue and multiprocessing.queues.Queue, which typeshed +# treats as the same object. +multiprocessing.queues.JoinableQueue.__init__ +multiprocessing.queues.Queue.__init__ +multiprocessing.queues.SimpleQueue.__init__ + +# These methods are dynamically created after object initialization, +# copied from a wrapped lock object. Stubtest doesn't think they exist +# because of that. +multiprocessing.synchronize.Condition.acquire +multiprocessing.synchronize.Condition.release +multiprocessing.synchronize.SemLock.acquire +multiprocessing.synchronize.SemLock.release + # C signature is broader than what is actually accepted _?queue.SimpleQueue.__init__ diff --git a/stdlib/multiprocessing/synchronize.pyi b/stdlib/multiprocessing/synchronize.pyi index d6f46b527..e3cbfbc0e 100644 --- a/stdlib/multiprocessing/synchronize.pyi +++ b/stdlib/multiprocessing/synchronize.pyi @@ -10,7 +10,7 @@ _LockLike: TypeAlias = Lock | RLock class Barrier(threading.Barrier): def __init__( - self, parties: int, action: Callable[[], object] | None = None, timeout: float | None = None, *ctx: BaseContext + self, parties: int, action: Callable[[], object] | None = None, timeout: float | None = None, *, ctx: BaseContext ) -> None: ... class Condition: @@ -19,12 +19,14 @@ class Condition: def notify_all(self) -> None: ... def wait(self, timeout: float | None = None) -> bool: ... def wait_for(self, predicate: Callable[[], bool], timeout: float | None = None) -> bool: ... - def acquire(self, block: bool = ..., timeout: float | None = ...) -> bool: ... - def release(self) -> None: ... def __enter__(self) -> bool: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None, / ) -> None: ... + # These methods are copied from the lock passed to the constructor, or an + # instance of ctx.RLock() if lock was None. + def acquire(self, block: bool = True, timeout: float | None = None) -> bool: ... + def release(self) -> None: ... class Event: def __init__(self, *, ctx: BaseContext) -> None: ... @@ -35,12 +37,14 @@ class Event: # Not part of public API class SemLock: - def acquire(self, block: bool = ..., timeout: float | None = ...) -> bool: ... - def release(self) -> None: ... + def __init__(self, kind: int, value: int, maxvalue: int, *, ctx: BaseContext | None) -> None: ... def __enter__(self) -> bool: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None, / ) -> None: ... + # These methods are copied from the wrapped _multiprocessing.SemLock object + def acquire(self, block: bool = True, timeout: float | None = None) -> bool: ... + def release(self) -> None: ... class Lock(SemLock): def __init__(self, *, ctx: BaseContext) -> None: ...