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

@@ -15,7 +15,6 @@ from typing import (
Iterator,
List,
Mapping,
Optional,
Protocol,
Tuple,
Type,
@@ -103,24 +102,24 @@ class HTTPResponse(io.BufferedIOBase, BinaryIO):
closed: bool
status: int
reason: str
def __init__(self, sock: socket, debuglevel: int = ..., method: Optional[str] = ..., url: Optional[str] = ...) -> None: ...
def __init__(self, sock: socket, debuglevel: int = ..., method: str | None = ..., url: str | None = ...) -> None: ...
def peek(self, n: int = ...) -> bytes: ...
def read(self, amt: Optional[int] = ...) -> bytes: ...
def read(self, amt: int | None = ...) -> bytes: ...
def read1(self, n: int = ...) -> bytes: ...
def readinto(self, b: WriteableBuffer) -> int: ...
def readline(self, limit: int = ...) -> bytes: ... # type: ignore
@overload
def getheader(self, name: str) -> Optional[str]: ...
def getheader(self, name: str) -> str | None: ...
@overload
def getheader(self, name: str, default: _T) -> Union[str, _T]: ...
def getheader(self, name: str, default: _T) -> str | _T: ...
def getheaders(self) -> List[Tuple[str, str]]: ...
def fileno(self) -> int: ...
def isclosed(self) -> bool: ...
def __iter__(self) -> Iterator[bytes]: ...
def __enter__(self: Self) -> Self: ...
def __exit__(
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[types.TracebackType]
) -> Optional[bool]: ...
self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
) -> bool | None: ...
def info(self) -> email.message.Message: ...
def geturl(self) -> str: ...
def getcode(self) -> int: ...
@@ -133,14 +132,14 @@ class _HTTPConnectionProtocol(Protocol):
def __call__(
self,
host: str,
port: Optional[int] = ...,
port: int | None = ...,
timeout: float = ...,
source_address: Optional[Tuple[str, int]] = ...,
source_address: Tuple[str, int] | None = ...,
blocksize: int = ...,
) -> HTTPConnection: ...
else:
def __call__(
self, host: str, port: Optional[int] = ..., timeout: float = ..., source_address: Optional[Tuple[str, int]] = ...
self, host: str, port: int | None = ..., timeout: float = ..., source_address: Tuple[str, int] | None = ...
) -> HTTPConnection: ...
class HTTPConnection:
@@ -148,7 +147,7 @@ class HTTPConnection:
debuglevel: int = ...
default_port: int = ... # undocumented
response_class: Type[HTTPResponse] = ... # undocumented
timeout: Optional[float]
timeout: float | None
host: str
port: int
sock: Any
@@ -156,36 +155,26 @@ class HTTPConnection:
def __init__(
self,
host: str,
port: Optional[int] = ...,
timeout: Optional[float] = ...,
source_address: Optional[Tuple[str, int]] = ...,
port: int | None = ...,
timeout: float | None = ...,
source_address: Tuple[str, int] | None = ...,
blocksize: int = ...,
) -> None: ...
else:
def __init__(
self,
host: str,
port: Optional[int] = ...,
timeout: Optional[float] = ...,
source_address: Optional[Tuple[str, int]] = ...,
self, host: str, port: int | None = ..., timeout: float | None = ..., source_address: Tuple[str, int] | None = ...
) -> None: ...
def request(
self,
method: str,
url: str,
body: Optional[_DataType] = ...,
headers: Mapping[str, str] = ...,
*,
encode_chunked: bool = ...,
self, method: str, url: str, body: _DataType | None = ..., headers: Mapping[str, str] = ..., *, encode_chunked: bool = ...
) -> None: ...
def getresponse(self) -> HTTPResponse: ...
def set_debuglevel(self, level: int) -> None: ...
def set_tunnel(self, host: str, port: Optional[int] = ..., headers: Optional[Mapping[str, str]] = ...) -> None: ...
def set_tunnel(self, host: str, port: int | None = ..., headers: Mapping[str, str] | None = ...) -> None: ...
def connect(self) -> None: ...
def close(self) -> None: ...
def putrequest(self, method: str, url: str, skip_host: bool = ..., skip_accept_encoding: bool = ...) -> None: ...
def putheader(self, header: str, *argument: str) -> None: ...
def endheaders(self, message_body: Optional[_DataType] = ..., *, encode_chunked: bool = ...) -> None: ...
def endheaders(self, message_body: _DataType | None = ..., *, encode_chunked: bool = ...) -> None: ...
def send(self, data: _DataType) -> None: ...
class HTTPSConnection(HTTPConnection):
@@ -193,28 +182,28 @@ class HTTPSConnection(HTTPConnection):
def __init__(
self,
host: str,
port: Optional[int] = ...,
key_file: Optional[str] = ...,
cert_file: Optional[str] = ...,
timeout: Optional[float] = ...,
source_address: Optional[Tuple[str, int]] = ...,
port: int | None = ...,
key_file: str | None = ...,
cert_file: str | None = ...,
timeout: float | None = ...,
source_address: Tuple[str, int] | None = ...,
*,
context: Optional[ssl.SSLContext] = ...,
check_hostname: Optional[bool] = ...,
context: ssl.SSLContext | None = ...,
check_hostname: bool | None = ...,
blocksize: int = ...,
) -> None: ...
else:
def __init__(
self,
host: str,
port: Optional[int] = ...,
key_file: Optional[str] = ...,
cert_file: Optional[str] = ...,
timeout: Optional[float] = ...,
source_address: Optional[Tuple[str, int]] = ...,
port: int | None = ...,
key_file: str | None = ...,
cert_file: str | None = ...,
timeout: float | None = ...,
source_address: Tuple[str, int] | None = ...,
*,
context: Optional[ssl.SSLContext] = ...,
check_hostname: Optional[bool] = ...,
context: ssl.SSLContext | None = ...,
check_hostname: bool | None = ...,
) -> None: ...
class HTTPException(Exception): ...
@@ -231,7 +220,7 @@ class UnknownTransferEncoding(HTTPException): ...
class UnimplementedFileMode(HTTPException): ...
class IncompleteRead(HTTPException):
def __init__(self, partial: bytes, expected: Optional[int] = ...) -> None: ...
def __init__(self, partial: bytes, expected: int | None = ...) -> None: ...
class ImproperConnectionState(HTTPException): ...
class CannotSendRequest(ImproperConnectionState): ...

View File

@@ -1,7 +1,7 @@
import sys
from _typeshed import StrPath
from http.client import HTTPResponse
from typing import ClassVar, Dict, Iterable, Iterator, Optional, Pattern, Sequence, Tuple, TypeVar, Union, overload
from typing import ClassVar, Dict, Iterable, Iterator, Pattern, Sequence, Tuple, TypeVar, overload
from urllib.request import Request
_T = TypeVar("_T")
@@ -15,14 +15,14 @@ class CookieJar(Iterable[Cookie]):
domain_re: ClassVar[Pattern[str]] = ... # undocumented
dots_re: ClassVar[Pattern[str]] = ... # undocumented
magic_re: ClassVar[Pattern[str]] = ... # undocumented
def __init__(self, policy: Optional[CookiePolicy] = ...) -> None: ...
def __init__(self, policy: CookiePolicy | None = ...) -> None: ...
def add_cookie_header(self, request: Request) -> None: ...
def extract_cookies(self, response: HTTPResponse, request: Request) -> None: ...
def set_policy(self, policy: CookiePolicy) -> None: ...
def make_cookies(self, response: HTTPResponse, request: Request) -> Sequence[Cookie]: ...
def set_cookie(self, cookie: Cookie) -> None: ...
def set_cookie_if_ok(self, cookie: Cookie, request: Request) -> None: ...
def clear(self, domain: Optional[str] = ..., path: Optional[str] = ..., name: Optional[str] = ...) -> None: ...
def clear(self, domain: str | None = ..., path: str | None = ..., name: str | None = ...) -> None: ...
def clear_session_cookies(self) -> None: ...
def clear_expired_cookies(self) -> None: ... # undocumented
def __iter__(self) -> Iterator[Cookie]: ...
@@ -34,16 +34,12 @@ class FileCookieJar(CookieJar):
filename: str
delayload: bool
if sys.version_info >= (3, 8):
def __init__(
self, filename: Optional[StrPath] = ..., delayload: bool = ..., policy: Optional[CookiePolicy] = ...
) -> None: ...
def __init__(self, filename: StrPath | None = ..., delayload: bool = ..., policy: CookiePolicy | None = ...) -> None: ...
else:
def __init__(
self, filename: Optional[str] = ..., delayload: bool = ..., policy: Optional[CookiePolicy] = ...
) -> None: ...
def save(self, filename: Optional[str] = ..., ignore_discard: bool = ..., ignore_expires: bool = ...) -> None: ...
def load(self, filename: Optional[str] = ..., ignore_discard: bool = ..., ignore_expires: bool = ...) -> None: ...
def revert(self, filename: Optional[str] = ..., ignore_discard: bool = ..., ignore_expires: bool = ...) -> None: ...
def __init__(self, filename: str | None = ..., delayload: bool = ..., policy: CookiePolicy | None = ...) -> None: ...
def save(self, filename: str | None = ..., ignore_discard: bool = ..., ignore_expires: bool = ...) -> None: ...
def load(self, filename: str | None = ..., ignore_discard: bool = ..., ignore_expires: bool = ...) -> None: ...
def revert(self, filename: str | None = ..., ignore_discard: bool = ..., ignore_expires: bool = ...) -> None: ...
class MozillaCookieJar(FileCookieJar):
header: ClassVar[str] = ... # undocumented
@@ -76,11 +72,11 @@ class DefaultCookiePolicy(CookiePolicy):
if sys.version_info >= (3, 8):
def __init__(
self,
blocked_domains: Optional[Sequence[str]] = ...,
allowed_domains: Optional[Sequence[str]] = ...,
blocked_domains: Sequence[str] | None = ...,
allowed_domains: Sequence[str] | None = ...,
netscape: bool = ...,
rfc2965: bool = ...,
rfc2109_as_netscape: Optional[bool] = ...,
rfc2109_as_netscape: bool | None = ...,
hide_cookie2: bool = ...,
strict_domain: bool = ...,
strict_rfc2965_unverifiable: bool = ...,
@@ -93,11 +89,11 @@ class DefaultCookiePolicy(CookiePolicy):
else:
def __init__(
self,
blocked_domains: Optional[Sequence[str]] = ...,
allowed_domains: Optional[Sequence[str]] = ...,
blocked_domains: Sequence[str] | None = ...,
allowed_domains: Sequence[str] | None = ...,
netscape: bool = ...,
rfc2965: bool = ...,
rfc2109_as_netscape: Optional[bool] = ...,
rfc2109_as_netscape: bool | None = ...,
hide_cookie2: bool = ...,
strict_domain: bool = ...,
strict_rfc2965_unverifiable: bool = ...,
@@ -109,8 +105,8 @@ class DefaultCookiePolicy(CookiePolicy):
def blocked_domains(self) -> Tuple[str, ...]: ...
def set_blocked_domains(self, blocked_domains: Sequence[str]) -> None: ...
def is_blocked(self, domain: str) -> bool: ...
def allowed_domains(self) -> Optional[Tuple[str, ...]]: ...
def set_allowed_domains(self, allowed_domains: Optional[Sequence[str]]) -> None: ...
def allowed_domains(self) -> Tuple[str, ...] | None: ...
def set_allowed_domains(self, allowed_domains: Sequence[str] | None) -> None: ...
def is_not_allowed(self, domain: str) -> bool: ...
def set_ok_version(self, cookie: Cookie, request: Request) -> bool: ... # undocumented
def set_ok_verifiability(self, cookie: Cookie, request: Request) -> bool: ... # undocumented
@@ -126,17 +122,17 @@ class DefaultCookiePolicy(CookiePolicy):
def return_ok_domain(self, cookie: Cookie, request: Request) -> bool: ... # undocumented
class Cookie:
version: Optional[int]
version: int | None
name: str
value: Optional[str]
port: Optional[str]
value: str | None
port: str | None
path: str
path_specified: bool
secure: bool
expires: Optional[int]
expires: int | None
discard: bool
comment: Optional[str]
comment_url: Optional[str]
comment: str | None
comment_url: str | None
rfc2109: bool
port_specified: bool
domain: str # undocumented
@@ -144,10 +140,10 @@ class Cookie:
domain_initial_dot: bool
def __init__(
self,
version: Optional[int],
version: int | None,
name: str,
value: Optional[str], # undocumented
port: Optional[str],
value: str | None, # undocumented
port: str | None,
port_specified: bool,
domain: str,
domain_specified: bool,
@@ -155,17 +151,17 @@ class Cookie:
path: str,
path_specified: bool,
secure: bool,
expires: Optional[int],
expires: int | None,
discard: bool,
comment: Optional[str],
comment_url: Optional[str],
comment: str | None,
comment_url: str | None,
rest: Dict[str, str],
rfc2109: bool = ...,
) -> None: ...
def has_nonstandard_attr(self, name: str) -> bool: ...
@overload
def get_nonstandard_attr(self, name: str) -> Optional[str]: ...
def get_nonstandard_attr(self, name: str) -> str | None: ...
@overload
def get_nonstandard_attr(self, name: str, default: _T) -> Union[str, _T]: ...
def get_nonstandard_attr(self, name: str, default: _T) -> str | _T: ...
def set_nonstandard_attr(self, name: str, value: str) -> None: ...
def is_expired(self, now: Optional[int] = ...) -> bool: ...
def is_expired(self, now: int | None = ...) -> bool: ...

View File

@@ -1,5 +1,5 @@
import sys
from typing import Any, Dict, Generic, Iterable, List, Mapping, Optional, Tuple, TypeVar, Union, overload
from typing import Any, Dict, Generic, Iterable, List, Mapping, Tuple, TypeVar, Union, overload
if sys.version_info >= (3, 9):
from types import GenericAlias
@@ -27,26 +27,26 @@ class Morsel(Dict[str, Any], Generic[_T]):
def set(self, key: str, val: str, coded_val: _T) -> None: ...
else:
def set(self, key: str, val: str, coded_val: _T, LegalChars: str = ...) -> None: ...
def setdefault(self, key: str, val: Optional[str] = ...) -> str: ...
def setdefault(self, key: str, val: str | None = ...) -> str: ...
# The dict update can also get a keywords argument so this is incompatible
@overload # type: ignore
def update(self, values: Mapping[str, str]) -> None: ...
@overload
def update(self, values: Iterable[Tuple[str, str]]) -> None: ...
def isReservedKey(self, K: str) -> bool: ...
def output(self, attrs: Optional[List[str]] = ..., header: str = ...) -> str: ...
def js_output(self, attrs: Optional[List[str]] = ...) -> str: ...
def OutputString(self, attrs: Optional[List[str]] = ...) -> str: ...
def output(self, attrs: List[str] | None = ..., header: str = ...) -> str: ...
def js_output(self, attrs: List[str] | None = ...) -> str: ...
def OutputString(self, attrs: List[str] | None = ...) -> str: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
class BaseCookie(Dict[str, Morsel[_T]], Generic[_T]):
def __init__(self, input: Optional[_DataType] = ...) -> None: ...
def __init__(self, input: _DataType | None = ...) -> None: ...
def value_decode(self, val: str) -> _T: ...
def value_encode(self, val: _T) -> str: ...
def output(self, attrs: Optional[List[str]] = ..., header: str = ..., sep: str = ...) -> str: ...
def js_output(self, attrs: Optional[List[str]] = ...) -> str: ...
def output(self, attrs: List[str] | None = ..., header: str = ..., sep: str = ...) -> str: ...
def js_output(self, attrs: List[str] | None = ...) -> str: ...
def load(self, rawdata: _DataType) -> None: ...
def __setitem__(self, key: str, value: Union[str, Morsel[_T]]) -> None: ...
def __setitem__(self, key: str, value: str | Morsel[_T]) -> None: ...
class SimpleCookie(BaseCookie[_T], Generic[_T]): ...

View File

@@ -3,7 +3,7 @@ import io
import socketserver
import sys
from _typeshed import StrPath, SupportsRead, SupportsWrite
from typing import Any, AnyStr, BinaryIO, ClassVar, Dict, List, Mapping, Optional, Sequence, Tuple, Union
from typing import Any, AnyStr, BinaryIO, ClassVar, Dict, List, Mapping, Sequence, Tuple
class HTTPServer(socketserver.TCPServer):
server_name: str
@@ -31,22 +31,22 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
responses: Mapping[int, Tuple[str, str]]
default_request_version: str # undocumented
weekdayname: ClassVar[Sequence[str]] = ... # undocumented
monthname: ClassVar[Sequence[Optional[str]]] = ... # undocumented
monthname: ClassVar[Sequence[str | None]] = ... # undocumented
def __init__(self, request: bytes, client_address: Tuple[str, int], server: socketserver.BaseServer) -> None: ...
def handle(self) -> None: ...
def handle_one_request(self) -> None: ...
def handle_expect_100(self) -> bool: ...
def send_error(self, code: int, message: Optional[str] = ..., explain: Optional[str] = ...) -> None: ...
def send_response(self, code: int, message: Optional[str] = ...) -> None: ...
def send_error(self, code: int, message: str | None = ..., explain: str | None = ...) -> None: ...
def send_response(self, code: int, message: str | None = ...) -> None: ...
def send_header(self, keyword: str, value: str) -> None: ...
def send_response_only(self, code: int, message: Optional[str] = ...) -> None: ...
def send_response_only(self, code: int, message: str | None = ...) -> None: ...
def end_headers(self) -> None: ...
def flush_headers(self) -> None: ...
def log_request(self, code: Union[int, str] = ..., size: Union[int, str] = ...) -> None: ...
def log_request(self, code: int | str = ..., size: int | str = ...) -> None: ...
def log_error(self, format: str, *args: Any) -> None: ...
def log_message(self, format: str, *args: Any) -> None: ...
def version_string(self) -> str: ...
def date_time_string(self, timestamp: Optional[int] = ...) -> str: ...
def date_time_string(self, timestamp: int | None = ...) -> str: ...
def log_date_time_string(self) -> str: ...
def address_string(self) -> str: ...
def parse_request(self) -> bool: ... # undocumented