mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 13:04:46 +08:00
socket: Some more address typing (#2695)
This commit is contained in:
committed by
Jelle Zijlstra
parent
fb8b77e715
commit
9b5976e15b
@@ -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 -----
|
||||
|
||||
Reference in New Issue
Block a user