Big diff: Use new "|" union syntax (#5872)

This commit is contained in:
Akuli
2021-08-08 12:05:21 +03:00
committed by GitHub
parent b9adb7a874
commit ee487304d7
578 changed files with 8080 additions and 8966 deletions

View File

@@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer, Self, WriteableBuffer
from collections.abc import Iterable
from enum import IntEnum, IntFlag
from io import RawIOBase
from typing import Any, BinaryIO, Optional, TextIO, TypeVar, Union, overload
from typing import Any, BinaryIO, TextIO, TypeVar, overload
from typing_extensions import Literal
# Ideally, we'd just do "from _socket import *". Unfortunately, socket
@@ -539,11 +539,7 @@ if sys.platform == "win32":
class socket(_socket.socket):
def __init__(
self,
family: Union[AddressFamily, int] = ...,
type: Union[SocketKind, int] = ...,
proto: int = ...,
fileno: Optional[int] = ...,
self, family: AddressFamily | int = ..., type: SocketKind | int = ..., proto: int = ..., fileno: int | None = ...
) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: object) -> None: ...
@@ -555,23 +551,23 @@ class socket(_socket.socket):
def makefile(
self,
mode: Literal["r", "w", "rw", "wr", ""] = ...,
buffering: Optional[int] = ...,
buffering: int | None = ...,
*,
encoding: Optional[str] = ...,
errors: Optional[str] = ...,
newline: Optional[str] = ...,
encoding: str | None = ...,
errors: str | None = ...,
newline: str | None = ...,
) -> TextIO: ...
@overload
def makefile(
self,
mode: Literal["b", "rb", "br", "wb", "bw", "rwb", "rbw", "wrb", "wbr", "brw", "bwr"],
buffering: Optional[int] = ...,
buffering: int | None = ...,
*,
encoding: Optional[str] = ...,
errors: Optional[str] = ...,
newline: Optional[str] = ...,
encoding: str | None = ...,
errors: str | None = ...,
newline: str | None = ...,
) -> BinaryIO: ...
def sendfile(self, file: BinaryIO, offset: int = ..., count: Optional[int] = ...) -> int: ...
def sendfile(self, file: BinaryIO, offset: int = ..., count: int | None = ...) -> int: ...
@property
def family(self) -> AddressFamily: ... # type: ignore
@property
@@ -585,7 +581,7 @@ if sys.platform != "win32":
if sys.version_info >= (3, 9):
# flags and address appear to be unused in send_fds and recv_fds
def send_fds(
sock: socket, buffers: Iterable[bytes], fds: Union[bytes, Iterable[int]], flags: int = ..., address: None = ...
sock: socket, buffers: Iterable[bytes], fds: bytes | Iterable[int], flags: int = ..., address: None = ...
) -> int: ...
def recv_fds(sock: socket, bufsize: int, maxfds: int, flags: int = ...) -> tuple[bytes, list[int], int, Any]: ...
@@ -597,13 +593,13 @@ if sys.platform == "win32":
else:
def socketpair( # type: ignore
family: Union[int, AddressFamily, None] = ..., type: Union[SocketType, int] = ..., proto: int = ...
family: int | AddressFamily | None = ..., type: SocketType | int = ..., proto: int = ...
) -> tuple[socket, socket]: ...
class SocketIO(RawIOBase):
def __init__(self, sock: socket, mode: Literal["r", "w", "rw", "rb", "wb", "rwb"]) -> None: ...
def readinto(self, b: WriteableBuffer) -> Optional[int]: ...
def write(self, b: ReadableBuffer) -> Optional[int]: ...
def readinto(self, b: WriteableBuffer) -> int | None: ...
def write(self, b: ReadableBuffer) -> int | None: ...
@property
def name(self) -> int: ... # return value is really "int"
@property
@@ -611,23 +607,23 @@ class SocketIO(RawIOBase):
def getfqdn(name: str = ...) -> str: ...
def create_connection(
address: tuple[Optional[str], int],
timeout: Optional[float] = ..., # noqa: F811
source_address: Optional[tuple[Union[bytearray, bytes, str], int]] = ...,
address: tuple[str | None, int],
timeout: float | None = ..., # noqa: F811
source_address: tuple[bytearray | bytes | str, int] | None = ...,
) -> socket: ...
if sys.version_info >= (3, 8):
def has_dualstack_ipv6() -> bool: ...
def create_server(
address: _Address, *, family: int = ..., backlog: Optional[int] = ..., reuse_port: bool = ..., dualstack_ipv6: bool = ...
address: _Address, *, family: int = ..., backlog: int | None = ..., reuse_port: bool = ..., dualstack_ipv6: bool = ...
) -> socket: ...
# the 5th tuple item is an address
def getaddrinfo(
host: Optional[Union[bytearray, bytes, str]],
port: Union[str, int, None],
host: bytearray | bytes | str | None,
port: str | int | None,
family: int = ...,
type: int = ...,
proto: int = ...,
flags: int = ...,
) -> list[tuple[AddressFamily, SocketKind, int, str, Union[tuple[str, int], tuple[str, int, int, int]]]]: ...
) -> list[tuple[AddressFamily, SocketKind, int, str, tuple[str, int] | tuple[str, int, int, int]]]: ...