Make the return type of multiprocessing.connection.Pipe more precise (#8706)

The precise return type depends on the platform. Link to implementation:
68fb03249f/Lib/multiprocessing/connection.py (L518)

Now users no longer need to use the internal-looking class
`_ConnectionBase` in annotations, at least in code that doesn't
need to be cross-platform.
This commit is contained in:
Jukka Lehtosalo
2022-09-08 13:24:49 +01:00
committed by GitHub
parent fdbf1396d1
commit e4d0d3d9d7
2 changed files with 23 additions and 3 deletions

View File

@@ -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]: ...