Use PEP 585 syntax in Python 2, protobuf & _ast stubs, where possible (#6949)

This commit is contained in:
Alex Waygood
2022-01-18 15:14:03 +00:00
committed by GitHub
parent aa885ecd65
commit 8af5e0d340
264 changed files with 2217 additions and 2411 deletions

View File

@@ -1,5 +1,5 @@
import sys
from typing import Any, BinaryIO, Iterable, List, Text, Tuple, Union, overload
from typing import Any, BinaryIO, Iterable, Text, Union, overload
# ----- Constants -----
# Some socket families are listed in the "Socket families" section of the docs,
@@ -373,13 +373,13 @@ 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[Any, ...], str]
_Address = Union[tuple[Any, ...], str]
_RetAddress = Any
# TODO Most methods allow bytes as address objects
_WriteBuffer = Union[bytearray, memoryview]
_CMSG = Tuple[int, int, bytes]
_CMSG = tuple[int, int, bytes]
class socket:
family: int
@@ -387,7 +387,7 @@ class socket:
proto: int
def __init__(self, family: int = ..., type: int = ..., proto: int = ...) -> None: ...
# --- methods ---
def accept(self) -> Tuple[socket, _RetAddress]: ...
def accept(self) -> tuple[socket, _RetAddress]: ...
def bind(self, address: _Address | bytes) -> None: ...
def close(self) -> None: ...
def connect(self, address: _Address | bytes) -> None: ...
@@ -403,13 +403,13 @@ class socket:
def getsockopt(self, level: int, optname: int, buflen: int) -> bytes: ...
def gettimeout(self) -> float | None: ...
if sys.platform == "win32":
def ioctl(self, control: int, option: int | Tuple[int, int, int]) -> None: ...
def ioctl(self, control: int, option: int | tuple[int, int, int]) -> None: ...
def listen(self, __backlog: int) -> None: ...
# Note that the makefile's documented windows-specific behavior is not represented
def makefile(self, mode: unicode = ..., buffering: int = ...) -> BinaryIO: ...
def recv(self, bufsize: int, flags: int = ...) -> bytes: ...
def recvfrom(self, bufsize: int, flags: int = ...) -> Tuple[bytes, _RetAddress]: ...
def recvfrom_into(self, buffer: _WriteBuffer, nbytes: int = ..., flags: int = ...) -> Tuple[int, _RetAddress]: ...
def recvfrom(self, bufsize: int, flags: int = ...) -> tuple[bytes, _RetAddress]: ...
def recvfrom_into(self, buffer: _WriteBuffer, nbytes: int = ..., 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
@@ -427,9 +427,9 @@ class socket:
# ----- Functions -----
def create_connection(
address: Tuple[str | None, int],
address: tuple[str | None, int],
timeout: float | None = ...,
source_address: Tuple[bytearray | bytes | Text, int] | None = ...,
source_address: tuple[bytearray | bytes | Text, int] | None = ...,
) -> socket: ...
def fromfd(fd: int, family: int, type: int, proto: int = ...) -> socket: ...
@@ -441,22 +441,22 @@ def getaddrinfo(
socktype: int = ...,
proto: int = ...,
flags: int = ...,
) -> List[Tuple[AddressFamily, SocketKind, int, str, Tuple[Any, ...]]]: ...
) -> list[tuple[AddressFamily, SocketKind, int, str, tuple[Any, ...]]]: ...
def getfqdn(name: str = ...) -> str: ...
def gethostbyname(hostname: str) -> str: ...
def gethostbyname_ex(hostname: str) -> Tuple[str, List[str], List[str]]: ...
def gethostbyname_ex(hostname: str) -> tuple[str, list[str], list[str]]: ...
def gethostname() -> str: ...
def gethostbyaddr(ip_address: str) -> Tuple[str, List[str], List[str]]: ...
def getnameinfo(sockaddr: Tuple[str, int] | Tuple[str, int, int, int], flags: int) -> Tuple[str, str]: ...
def gethostbyaddr(ip_address: str) -> tuple[str, list[str], list[str]]: ...
def getnameinfo(sockaddr: tuple[str, int] | tuple[str, int, int, int], flags: int) -> tuple[str, str]: ...
def getprotobyname(protocolname: str) -> int: ...
def getservbyname(servicename: str, protocolname: str = ...) -> int: ...
def getservbyport(port: int, protocolname: str = ...) -> str: ...
if sys.platform == "win32":
def socketpair(family: int = ..., type: int = ..., proto: int = ...) -> Tuple[socket, socket]: ...
def socketpair(family: int = ..., type: int = ..., proto: int = ...) -> tuple[socket, socket]: ...
else:
def socketpair(family: int | None = ..., type: int = ..., proto: int = ...) -> Tuple[socket, socket]: ...
def socketpair(family: int | None = ..., type: int = ..., proto: int = ...) -> tuple[socket, socket]: ...
def ntohl(x: int) -> int: ... # param & ret val are 32-bit ints
def ntohs(x: int) -> int: ... # param & ret val are 16-bit ints