Skip to content

Commit

Permalink
Typeshed cherry-pick: Make the return type of multiprocessing.connect…
Browse files Browse the repository at this point in the history
…ion.Pipe more precise (#8706)
  • Loading branch information
jhance committed Sep 9, 2022
1 parent 5d08c47 commit 9dc1f1a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 9 additions & 1 deletion mypy/typeshed/stdlib/multiprocessing/connection.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ def wait(
object_list: Iterable[Connection | socket.socket | int], timeout: float | None = ...
) -> list[Connection | socket.socket | int]: ...
def Client(address: _Address, family: str | None = ..., authkey: bytes | None = ...) -> Connection: ...
def Pipe(duplex: bool = ...) -> tuple[_ConnectionBase, _ConnectionBase]: ...

# N.B. Keep this in sync with multiprocessing.context.BaseContext.Pipe.
# _ConnectionBase is the common base class of Connection and PipeConnection
# and can be used in cross-platform code.
if sys.platform != "win32":
def Pipe(duplex: bool = ...) -> tuple[Connection, Connection]: ...

else:
def Pipe(duplex: bool = ...) -> tuple[PipeConnection, PipeConnection]: ...
16 changes: 14 additions & 2 deletions mypy/typeshed/stdlib/multiprocessing/context.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ from collections.abc import Callable, Iterable, Sequence
from ctypes import _CData
from logging import Logger
from multiprocessing import popen_fork, popen_forkserver, popen_spawn_posix, popen_spawn_win32, queues, synchronize
from multiprocessing.connection import _ConnectionBase
from multiprocessing.managers import SyncManager
from multiprocessing.pool import Pool as _Pool
from multiprocessing.process import BaseProcess
from multiprocessing.sharedctypes import SynchronizedArray, SynchronizedBase
from typing import Any, ClassVar, TypeVar, overload
from typing_extensions import Literal, TypeAlias

if sys.platform != "win32":
from multiprocessing.connection import Connection
else:
from multiprocessing.connection import PipeConnection

if sys.version_info >= (3, 8):
__all__ = ()
else:
Expand Down Expand Up @@ -43,7 +47,15 @@ class BaseContext:
def active_children() -> list[BaseProcess]: ...
def cpu_count(self) -> int: ...
def Manager(self) -> SyncManager: ...
def Pipe(self, duplex: bool = ...) -> tuple[_ConnectionBase, _ConnectionBase]: ...

# N.B. Keep this in sync with multiprocessing.connection.Pipe.
# _ConnectionBase is the common base class of Connection and PipeConnection
# and can be used in cross-platform code.
if sys.platform != "win32":
def Pipe(self, duplex: bool = ...) -> tuple[Connection, Connection]: ...
else:
def Pipe(self, duplex: bool = ...) -> tuple[PipeConnection, PipeConnection]: ...

def Barrier(
self, parties: int, action: Callable[..., object] | None = ..., timeout: float | None = ...
) -> synchronize.Barrier: ...
Expand Down

0 comments on commit 9dc1f1a

Please sign in to comment.