Skip to content

Commit 9dc1f1a

Browse files
committed
Typeshed cherry-pick: Make the return type of multiprocessing.connection.Pipe more precise (#8706)
1 parent 5d08c47 commit 9dc1f1a

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

mypy/typeshed/stdlib/multiprocessing/connection.pyi

+9-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,12 @@ def wait(
5858
object_list: Iterable[Connection | socket.socket | int], timeout: float | None = ...
5959
) -> list[Connection | socket.socket | int]: ...
6060
def Client(address: _Address, family: str | None = ..., authkey: bytes | None = ...) -> Connection: ...
61-
def Pipe(duplex: bool = ...) -> tuple[_ConnectionBase, _ConnectionBase]: ...
61+
62+
# N.B. Keep this in sync with multiprocessing.context.BaseContext.Pipe.
63+
# _ConnectionBase is the common base class of Connection and PipeConnection
64+
# and can be used in cross-platform code.
65+
if sys.platform != "win32":
66+
def Pipe(duplex: bool = ...) -> tuple[Connection, Connection]: ...
67+
68+
else:
69+
def Pipe(duplex: bool = ...) -> tuple[PipeConnection, PipeConnection]: ...

mypy/typeshed/stdlib/multiprocessing/context.pyi

+14-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ from collections.abc import Callable, Iterable, Sequence
44
from ctypes import _CData
55
from logging import Logger
66
from multiprocessing import popen_fork, popen_forkserver, popen_spawn_posix, popen_spawn_win32, queues, synchronize
7-
from multiprocessing.connection import _ConnectionBase
87
from multiprocessing.managers import SyncManager
98
from multiprocessing.pool import Pool as _Pool
109
from multiprocessing.process import BaseProcess
1110
from multiprocessing.sharedctypes import SynchronizedArray, SynchronizedBase
1211
from typing import Any, ClassVar, TypeVar, overload
1312
from typing_extensions import Literal, TypeAlias
1413

14+
if sys.platform != "win32":
15+
from multiprocessing.connection import Connection
16+
else:
17+
from multiprocessing.connection import PipeConnection
18+
1519
if sys.version_info >= (3, 8):
1620
__all__ = ()
1721
else:
@@ -43,7 +47,15 @@ class BaseContext:
4347
def active_children() -> list[BaseProcess]: ...
4448
def cpu_count(self) -> int: ...
4549
def Manager(self) -> SyncManager: ...
46-
def Pipe(self, duplex: bool = ...) -> tuple[_ConnectionBase, _ConnectionBase]: ...
50+
51+
# N.B. Keep this in sync with multiprocessing.connection.Pipe.
52+
# _ConnectionBase is the common base class of Connection and PipeConnection
53+
# and can be used in cross-platform code.
54+
if sys.platform != "win32":
55+
def Pipe(self, duplex: bool = ...) -> tuple[Connection, Connection]: ...
56+
else:
57+
def Pipe(self, duplex: bool = ...) -> tuple[PipeConnection, PipeConnection]: ...
58+
4759
def Barrier(
4860
self, parties: int, action: Callable[..., object] | None = ..., timeout: float | None = ...
4961
) -> synchronize.Barrier: ...

0 commit comments

Comments
 (0)