Skip to content

stdlib: use PEP 604 in most places #5564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 5 additions & 5 deletions stdlib/@python2/BaseHTTPServer.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mimetools
import SocketServer
from typing import Any, BinaryIO, Callable, Mapping, Optional, Tuple, Union
from typing import Any, BinaryIO, Callable, Mapping, Tuple

class HTTPServer(SocketServer.TCPServer):
server_name: str
Expand All @@ -27,15 +27,15 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
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 send_error(self, code: int, message: Optional[str] = ...) -> None: ...
def send_response(self, code: int, message: Optional[str] = ...) -> None: ...
def send_error(self, code: int, message: str | None = ...) -> None: ...
def send_response(self, code: int, message: str | None = ...) -> None: ...
def send_header(self, keyword: str, value: str) -> 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: ...
8 changes: 4 additions & 4 deletions stdlib/@python2/ConfigParser.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from _typeshed import SupportsNoArgReadline
from typing import IO, Any, Dict, List, Optional, Sequence, Tuple, Union
from typing import IO, Any, Dict, List, Sequence, Tuple

DEFAULTSECT: str
MAX_INTERPOLATION_DEPTH: int
Expand Down Expand Up @@ -65,7 +65,7 @@ class RawConfigParser:
def add_section(self, section: str) -> None: ...
def has_section(self, section: str) -> bool: ...
def options(self, section: str) -> List[str]: ...
def read(self, filenames: Union[str, Sequence[str]]) -> List[str]: ...
def read(self, filenames: str | Sequence[str]) -> List[str]: ...
def readfp(self, fp: SupportsNoArgReadline[str], filename: str = ...) -> None: ...
def get(self, section: str, option: str) -> str: ...
def items(self, section: str) -> List[Tuple[Any, Any]]: ...
Expand All @@ -84,8 +84,8 @@ class RawConfigParser:

class ConfigParser(RawConfigParser):
_KEYCRE: Any
def get(self, section: str, option: str, raw: bool = ..., vars: Optional[Dict[Any, Any]] = ...) -> Any: ...
def items(self, section: str, raw: bool = ..., vars: Optional[Dict[Any, Any]] = ...) -> List[Tuple[str, Any]]: ...
def get(self, section: str, option: str, raw: bool = ..., vars: Dict[Any, Any] | None = ...) -> Any: ...
def items(self, section: str, raw: bool = ..., vars: Dict[Any, Any] | None = ...) -> List[Tuple[str, Any]]: ...
def _interpolate(self, section: str, option: str, rawval: Any, vars: Any) -> str: ...
def _interpolation_replace(self, match: Any) -> str: ...

Expand Down
18 changes: 9 additions & 9 deletions stdlib/@python2/Cookie.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional
from typing import Any, Dict

class CookieError(Exception): ...

Expand All @@ -10,30 +10,30 @@ class Morsel(Dict[Any, Any]):
value: Any
coded_value: Any
def set(self, key, val, coded_val, LegalChars=..., idmap=..., translate=...): ...
def output(self, attrs: Optional[Any] = ..., header=...): ...
def js_output(self, attrs: Optional[Any] = ...): ...
def OutputString(self, attrs: Optional[Any] = ...): ...
def output(self, attrs: Any | None = ..., header=...): ...
def js_output(self, attrs: Any | None = ...): ...
def OutputString(self, attrs: Any | None = ...): ...

class BaseCookie(Dict[Any, Any]):
def value_decode(self, val): ...
def value_encode(self, val): ...
def __init__(self, input: Optional[Any] = ...): ...
def __init__(self, input: Any | None = ...): ...
def __setitem__(self, key, value): ...
def output(self, attrs: Optional[Any] = ..., header=..., sep=...): ...
def js_output(self, attrs: Optional[Any] = ...): ...
def output(self, attrs: Any | None = ..., header=..., sep=...): ...
def js_output(self, attrs: Any | None = ...): ...
def load(self, rawdata): ...

class SimpleCookie(BaseCookie):
def value_decode(self, val): ...
def value_encode(self, val): ...

class SerialCookie(BaseCookie):
def __init__(self, input: Optional[Any] = ...): ...
def __init__(self, input: Any | None = ...): ...
def value_decode(self, val): ...
def value_encode(self, val): ...

class SmartCookie(BaseCookie):
def __init__(self, input: Optional[Any] = ...): ...
def __init__(self, input: Any | None = ...): ...
def value_decode(self, val): ...
def value_encode(self, val): ...

Expand Down
6 changes: 3 additions & 3 deletions stdlib/@python2/Queue.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Deque, Generic, Optional, TypeVar
from typing import Any, Deque, Generic, TypeVar

_T = TypeVar("_T")

Expand All @@ -19,9 +19,9 @@ class Queue(Generic[_T]):
def qsize(self) -> int: ...
def empty(self) -> bool: ...
def full(self) -> bool: ...
def put(self, item: _T, block: bool = ..., timeout: Optional[float] = ...) -> None: ...
def put(self, item: _T, block: bool = ..., timeout: float | None = ...) -> None: ...
def put_nowait(self, item: _T) -> None: ...
def get(self, block: bool = ..., timeout: Optional[float] = ...) -> _T: ...
def get(self, block: bool = ..., timeout: float | None = ...) -> _T: ...
def get_nowait(self) -> _T: ...

class PriorityQueue(Queue[_T]): ...
Expand Down
8 changes: 4 additions & 4 deletions stdlib/@python2/SimpleHTTPServer.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import BaseHTTPServer
from StringIO import StringIO
from typing import IO, Any, AnyStr, Mapping, Optional, Union
from typing import IO, Any, AnyStr, Mapping

class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
server_version: str
def do_GET(self) -> None: ...
def do_HEAD(self) -> None: ...
def send_head(self) -> Optional[IO[str]]: ...
def list_directory(self, path: Union[str, unicode]) -> Optional[StringIO[Any]]: ...
def send_head(self) -> IO[str] | None: ...
def list_directory(self, path: str | unicode) -> StringIO[Any] | None: ...
def translate_path(self, path: AnyStr) -> AnyStr: ...
def copyfile(self, source: IO[AnyStr], outputfile: IO[AnyStr]): ...
def guess_type(self, path: Union[str, unicode]) -> str: ...
def guess_type(self, path: str | unicode) -> str: ...
extensions_map: Mapping[str, str]
18 changes: 9 additions & 9 deletions stdlib/@python2/SocketServer.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from socket import SocketType
from typing import Any, BinaryIO, Callable, ClassVar, List, Optional, Text, Tuple, Union
from typing import Any, BinaryIO, Callable, ClassVar, List, Text, Tuple

class BaseServer:
address_family: int
Expand All @@ -10,7 +10,7 @@ class BaseServer:
allow_reuse_address: bool
request_queue_size: int
socket_type: int
timeout: Optional[float]
timeout: float | None
def __init__(self, server_address: Any, RequestHandlerClass: Callable[..., BaseRequestHandler]) -> None: ...
def fileno(self) -> int: ...
def handle_request(self) -> None: ...
Expand Down Expand Up @@ -46,22 +46,22 @@ if sys.platform != "win32":
class UnixStreamServer(BaseServer):
def __init__(
self,
server_address: Union[Text, bytes],
server_address: Text | bytes,
RequestHandlerClass: Callable[..., BaseRequestHandler],
bind_and_activate: bool = ...,
) -> None: ...
class UnixDatagramServer(BaseServer):
def __init__(
self,
server_address: Union[Text, bytes],
server_address: Text | bytes,
RequestHandlerClass: Callable[..., BaseRequestHandler],
bind_and_activate: bool = ...,
) -> None: ...

if sys.platform != "win32":
class ForkingMixIn:
timeout: Optional[float] # undocumented
active_children: Optional[List[int]] # undocumented
timeout: float | None # undocumented
active_children: List[int] | None # undocumented
max_children: int # undocumented
def collect_children(self) -> None: ... # undocumented
def handle_timeout(self) -> None: ... # undocumented
Expand All @@ -85,8 +85,8 @@ if sys.platform != "win32":

class BaseRequestHandler:
# Those are technically of types, respectively:
# * Union[SocketType, Tuple[bytes, SocketType]]
# * Union[Tuple[str, int], str]
# * SocketType | Tuple[bytes, SocketType]
# * Tuple[str, int] | str
# But there are some concerns that having unions here would cause
# too much inconvenience to people using it (see
# https://github.com/python/typeshed/pull/384#issuecomment-234649696)
Expand All @@ -101,7 +101,7 @@ class BaseRequestHandler:
class StreamRequestHandler(BaseRequestHandler):
rbufsize: ClassVar[int] # Undocumented
wbufsize: ClassVar[int] # Undocumented
timeout: ClassVar[Optional[float]] # Undocumented
timeout: ClassVar[float | None] # Undocumented
disable_nagle_algorithm: ClassVar[bool] # Undocumented
connection: SocketType # Undocumented
rfile: BinaryIO
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/StringIO.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import IO, Any, AnyStr, Generic, Iterable, Iterator, List, Optional
from typing import IO, Any, AnyStr, Generic, Iterable, Iterator, List

class StringIO(IO[AnyStr], Generic[AnyStr]):
closed: bool
Expand All @@ -15,7 +15,7 @@ class StringIO(IO[AnyStr], Generic[AnyStr]):
def read(self, n: int = ...) -> AnyStr: ...
def readline(self, length: int = ...) -> AnyStr: ...
def readlines(self, sizehint: int = ...) -> List[AnyStr]: ...
def truncate(self, size: Optional[int] = ...) -> int: ...
def truncate(self, size: int | None = ...) -> int: ...
def write(self, s: AnyStr) -> int: ...
def writelines(self, iterable: Iterable[AnyStr]) -> None: ...
def flush(self) -> None: ...
Expand Down
21 changes: 3 additions & 18 deletions stdlib/@python2/UserDict.pyi
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
from typing import (
Any,
Container,
Dict,
Generic,
Iterable,
Iterator,
List,
Mapping,
Optional,
Sized,
Tuple,
TypeVar,
Union,
overload,
)
from typing import Any, Container, Dict, Generic, Iterable, Iterator, List, Mapping, Sized, Tuple, TypeVar, overload

_KT = TypeVar("_KT")
_VT = TypeVar("_VT")
Expand All @@ -33,9 +18,9 @@ class DictMixin(Iterable[_KT], Container[_KT], Sized, Generic[_KT, _VT]):
# From typing.Mapping[_KT, _VT]
# (can't inherit because of keys())
@overload
def get(self, k: _KT) -> Optional[_VT]: ...
def get(self, k: _KT) -> _VT | None: ...
@overload
def get(self, k: _KT, default: Union[_VT, _T]) -> Union[_VT, _T]: ...
def get(self, k: _KT, default: _VT | _T) -> _VT | _T: ...
def values(self) -> List[_VT]: ...
def items(self) -> List[Tuple[_KT, _VT]]: ...
def iterkeys(self) -> Iterator[_KT]: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/@python2/UserList.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Iterable, List, MutableSequence, TypeVar, Union, overload
from typing import Iterable, List, MutableSequence, TypeVar, overload

_T = TypeVar("_T")
_S = TypeVar("_S")
Expand All @@ -10,7 +10,7 @@ class UserList(MutableSequence[_T]):
def __setitem__(self, i: int, o: _T) -> None: ...
@overload
def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ...
def __delitem__(self, i: Union[int, slice]) -> None: ...
def __delitem__(self, i: int | slice) -> None: ...
def __len__(self) -> int: ...
@overload
def __getitem__(self, i: int) -> _T: ...
Expand Down
24 changes: 12 additions & 12 deletions stdlib/@python2/UserString.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Iterable, List, MutableSequence, Optional, Sequence, Text, Tuple, TypeVar, Union, overload
from typing import Any, Iterable, List, MutableSequence, Sequence, Text, Tuple, TypeVar, overload

_UST = TypeVar("_UST", bound=UserString)
_MST = TypeVar("_MST", bound=MutableString)
Expand All @@ -24,9 +24,9 @@ class UserString(Sequence[UserString]):
def capitalize(self: _UST) -> _UST: ...
def center(self: _UST, width: int, *args: Any) -> _UST: ...
def count(self, sub: int, start: int = ..., end: int = ...) -> int: ...
def decode(self: _UST, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> _UST: ...
def encode(self: _UST, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> _UST: ...
def endswith(self, suffix: Union[Text, Tuple[Text, ...]], start: Optional[int] = ..., end: Optional[int] = ...) -> bool: ...
def decode(self: _UST, encoding: str | None = ..., errors: str | None = ...) -> _UST: ...
def encode(self: _UST, encoding: str | None = ..., errors: str | None = ...) -> _UST: ...
def endswith(self, suffix: Text | Tuple[Text, ...], start: int | None = ..., end: int | None = ...) -> bool: ...
def expandtabs(self: _UST, tabsize: int = ...) -> _UST: ...
def find(self, sub: Text, start: int = ..., end: int = ...) -> int: ...
def index(self, sub: Text, start: int = ..., end: int = ...) -> int: ...
Expand All @@ -42,19 +42,19 @@ class UserString(Sequence[UserString]):
def join(self, seq: Iterable[Text]) -> Text: ...
def ljust(self: _UST, width: int, *args: Any) -> _UST: ...
def lower(self: _UST) -> _UST: ...
def lstrip(self: _UST, chars: Optional[Text] = ...) -> _UST: ...
def lstrip(self: _UST, chars: Text | None = ...) -> _UST: ...
def partition(self, sep: Text) -> Tuple[Text, Text, Text]: ...
def replace(self: _UST, old: Text, new: Text, maxsplit: int = ...) -> _UST: ...
def rfind(self, sub: Text, start: int = ..., end: int = ...) -> int: ...
def rindex(self, sub: Text, start: int = ..., end: int = ...) -> int: ...
def rjust(self: _UST, width: int, *args: Any) -> _UST: ...
def rpartition(self, sep: Text) -> Tuple[Text, Text, Text]: ...
def rstrip(self: _UST, chars: Optional[Text] = ...) -> _UST: ...
def split(self, sep: Optional[Text] = ..., maxsplit: int = ...) -> List[Text]: ...
def rsplit(self, sep: Optional[Text] = ..., maxsplit: int = ...) -> List[Text]: ...
def rstrip(self: _UST, chars: Text | None = ...) -> _UST: ...
def split(self, sep: Text | None = ..., maxsplit: int = ...) -> List[Text]: ...
def rsplit(self, sep: Text | None = ..., maxsplit: int = ...) -> List[Text]: ...
def splitlines(self, keepends: int = ...) -> List[Text]: ...
def startswith(self, prefix: Union[Text, Tuple[Text, ...]], start: Optional[int] = ..., end: Optional[int] = ...) -> bool: ...
def strip(self: _UST, chars: Optional[Text] = ...) -> _UST: ...
def startswith(self, prefix: Text | Tuple[Text, ...], start: int | None = ..., end: int | None = ...) -> bool: ...
def strip(self: _UST, chars: Text | None = ...) -> _UST: ...
def swapcase(self: _UST) -> _UST: ...
def title(self: _UST) -> _UST: ...
def translate(self: _UST, *args: Any) -> _UST: ...
Expand All @@ -66,8 +66,8 @@ class MutableString(UserString, MutableSequence[MutableString]):
def __getitem__(self: _MST, i: int) -> _MST: ...
@overload
def __getitem__(self: _MST, s: slice) -> _MST: ...
def __setitem__(self, index: Union[int, slice], sub: Any) -> None: ...
def __delitem__(self, index: Union[int, slice]) -> None: ...
def __setitem__(self, index: int | slice, sub: Any) -> None: ...
def __delitem__(self, index: int | slice) -> None: ...
def immutable(self) -> UserString: ...
def __iadd__(self: _MST, other: Any) -> _MST: ...
def __imul__(self, n: int) -> _MST: ...
Expand Down
Loading