diff --git a/stdlib/2and3/socket.pyi b/stdlib/2and3/socket.pyi index b787dd868..b2e8fe272 100644 --- a/stdlib/2and3/socket.pyi +++ b/stdlib/2and3/socket.pyi @@ -497,6 +497,9 @@ class timeout(error): # Addresses can be either tuples of varying lengths (AF_INET, AF_INET6, # AF_NETLINK, AF_TIPC) or strings (AF_UNIX). +_Address = Union[tuple, str] +_RetAddress = Any + # TODO AF_PACKET and AF_BLUETOOTH address objects _CMSG = Tuple[int, int, bytes] @@ -518,18 +521,16 @@ class socket: def __exit__(self, *args: Any) -> None: ... # --- methods --- - # second tuple item is an address - def accept(self) -> Tuple[socket, Any]: ... - def bind(self, address: Union[tuple, str, bytes]) -> None: ... + def accept(self) -> Tuple[socket, _RetAddress]: ... + def bind(self, address: Union[_Address, bytes]) -> None: ... def close(self) -> None: ... - def connect(self, address: Union[tuple, str, bytes]) -> None: ... - def connect_ex(self, address: Union[tuple, str, bytes]) -> int: ... + def connect(self, address: Union[_Address, bytes]) -> None: ... + def connect_ex(self, address: Union[_Address, bytes]) -> int: ... def detach(self) -> int: ... def fileno(self) -> int: ... - # return value is an address - def getpeername(self) -> Any: ... - def getsockname(self) -> Any: ... + def getpeername(self) -> _RetAddress: ... + def getsockname(self) -> _RetAddress: ... @overload def getsockopt(self, level: int, optname: int) -> int: ... @@ -550,19 +551,18 @@ class socket: ... def recv(self, bufsize: int, flags: int = ...) -> bytes: ... - # Any in return type is an address - def recvfrom(self, bufsize: int, flags: int = ...) -> Tuple[bytes, Any]: ... + def recvfrom(self, bufsize: int, flags: int = ...) -> Tuple[bytes, _RetAddress]: ... def recvfrom_into(self, buffer: _WriteBuffer, nbytes: int, - flags: int = ...) -> Tuple[int, Any]: ... + flags: int = ...) -> Tuple[int, _RetAddress]: ... def recv_into(self, buffer: _WriteBuffer, nbytes: int, flags: int = ...) -> int: ... def send(self, data: bytes, flags: int = ...) -> int: ... def sendall(self, data: bytes, flags: int = ...) -> None: ... # return type: None on success @overload - def sendto(self, data: bytes, address: Union[tuple, str]) -> int: ... + def sendto(self, data: bytes, address: _Address) -> int: ... @overload - def sendto(self, data: bytes, flags: int, address: Union[tuple, str]) -> int: ... + def sendto(self, data: bytes, flags: int, address: _Address) -> int: ... def setblocking(self, flag: bool) -> None: ... def settimeout(self, value: Optional[float]) -> None: ... def setsockopt(self, level: int, optname: int, value: Union[int, bytes]) -> None: ... @@ -574,7 +574,7 @@ class socket: def recvmsg_into(self, __buffers: Iterable[_WriteBuffer], __ancbufsize: int = ..., __flags: int = ...) -> Tuple[int, List[_CMSG], int, Any]: ... def sendmsg(self, __buffers: Iterable[bytes], __ancdata: Iterable[_CMSG] = ..., - __flags: int = ..., __address: Any = ...) -> int: ... + __flags: int = ..., __address: _Address = ...) -> int: ... # ----- functions -----