Skip to content

Commit b9fae9d

Browse files
committed
[multiprocessing] Clarify incomplete popen types
1 parent 11c7821 commit b9fae9d

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

stdlib/multiprocessing/context.pyi

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ if sys.platform != "win32":
201201
Process: ClassVar[type[ForkServerProcess]]
202202

203203
def _force_start_method(method: str) -> None: ...
204-
def get_spawning_popen() -> Any | None: ...
205-
def set_spawning_popen(popen: Any) -> None: ...
204+
205+
if sys.platform != "win32":
206+
def get_spawning_popen() -> popen_forkserver.Popen | popen_spawn_posix.Popen | None: ...
207+
def set_spawning_popen(popen: popen_forkserver.Popen | popen_spawn_posix.Popen | None) -> None: ...
208+
209+
else:
210+
def get_spawning_popen() -> popen_forkserver.Popen | popen_spawn_win32.Popen | None: ...
211+
def set_spawning_popen(popen: popen_forkserver.Popen | popen_spawn_win32.Popen | None) -> None: ...
212+
206213
def assert_spawning(obj: Any) -> None: ...

stdlib/multiprocessing/heap.pyi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
2-
from _typeshed import Incomplete
32
from collections.abc import Callable
43
from mmap import mmap
4+
from multiprocessing import popen_forkserver, popen_spawn_posix, resource_sharer
55
from typing import Protocol, type_check_only
66
from typing_extensions import TypeAlias
77

@@ -24,7 +24,12 @@ if sys.platform != "win32":
2424
class _SupportsDetach(Protocol):
2525
def detach(self) -> int: ...
2626

27-
def reduce_arena(a: Arena) -> tuple[Callable[[int, _SupportsDetach], Arena], tuple[int, Incomplete]]: ...
27+
def reduce_arena(
28+
a: Arena,
29+
) -> tuple[
30+
Callable[[int, _SupportsDetach], Arena],
31+
tuple[int, popen_forkserver._DupFd | popen_spawn_posix._DupFd | resource_sharer.DupFd],
32+
]: ...
2833
def rebuild_arena(size: int, dupfd: _SupportsDetach) -> Arena: ...
2934

3035
class Heap:

stdlib/multiprocessing/reduction.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from abc import ABCMeta
66
from builtins import type as Type # alias to avoid name clash
77
from collections.abc import Callable
88
from copyreg import _DispatchTableType
9-
from multiprocessing import connection
9+
from multiprocessing import connection, popen_forkserver, popen_spawn_posix, resource_sharer
1010
from socket import socket
1111
from typing import Any, Final
1212

@@ -50,7 +50,7 @@ else:
5050
def send_handle(conn: HasFileno, handle: int, destination_pid: Unused) -> None: ...
5151
def recv_handle(conn: HasFileno) -> int: ...
5252
def sendfds(sock: socket, fds: list[int]) -> None: ...
53-
def DupFd(fd: int) -> Any: ... # Return type is really hard to get right
53+
def DupFd(fd: int) -> popen_forkserver._DupFd | popen_spawn_posix._DupFd | resource_sharer.DupFd: ...
5454

5555
# These aliases are to work around pyright complaints.
5656
# Pyright doesn't like it when a class object is defined as an alias

0 commit comments

Comments
 (0)