diff --git a/stdlib/__future__.pyi b/stdlib/__future__.pyi index 80fb06a228a7..a90cf1eddab7 100644 --- a/stdlib/__future__.pyi +++ b/stdlib/__future__.pyi @@ -1,4 +1,3 @@ -import sys from typing_extensions import TypeAlias _VersionInfo: TypeAlias = tuple[int, int, int, str, int] @@ -18,9 +17,7 @@ unicode_literals: _Feature with_statement: _Feature barry_as_FLUFL: _Feature generator_stop: _Feature - -if sys.version_info >= (3, 7): - annotations: _Feature +annotations: _Feature all_feature_names: list[str] # undocumented @@ -35,7 +32,5 @@ __all__ = [ "with_statement", "barry_as_FLUFL", "generator_stop", + "annotations", ] - -if sys.version_info >= (3, 7): - __all__ += ["annotations"] diff --git a/stdlib/_curses.pyi b/stdlib/_curses.pyi index 1d10e93c5f92..adb1ea84e45b 100644 --- a/stdlib/_curses.pyi +++ b/stdlib/_curses.pyi @@ -60,8 +60,7 @@ if sys.platform != "win32": A_DIM: int A_HORIZONTAL: int A_INVIS: int - if sys.version_info >= (3, 7): - A_ITALIC: int + A_ITALIC: int A_LEFT: int A_LOW: int A_NORMAL: int diff --git a/stdlib/_decimal.pyi b/stdlib/_decimal.pyi index 515ed13d2a63..71dff44658be 100644 --- a/stdlib/_decimal.pyi +++ b/stdlib/_decimal.pyi @@ -26,9 +26,7 @@ ROUND_FLOOR: str ROUND_UP: str ROUND_HALF_DOWN: str ROUND_05UP: str - -if sys.version_info >= (3, 7): - HAVE_CONTEXTVAR: bool +HAVE_CONTEXTVAR: bool HAVE_THREADS: bool MAX_EMAX: int MAX_PREC: int diff --git a/stdlib/_dummy_thread.pyi b/stdlib/_dummy_thread.pyi index 4bcf84964add..4cc9b9bc1b77 100644 --- a/stdlib/_dummy_thread.pyi +++ b/stdlib/_dummy_thread.pyi @@ -1,12 +1,8 @@ -import sys from collections.abc import Callable from types import TracebackType from typing import Any, NoReturn -__all__ = ["error", "start_new_thread", "exit", "get_ident", "allocate_lock", "interrupt_main", "LockType"] - -if sys.version_info >= (3, 7): - __all__ += ["RLock"] +__all__ = ["error", "start_new_thread", "exit", "get_ident", "allocate_lock", "interrupt_main", "LockType", "RLock"] TIMEOUT_MAX: int error = RuntimeError @@ -26,8 +22,7 @@ class LockType: def release(self) -> bool: ... def locked(self) -> bool: ... -if sys.version_info >= (3, 7): - class RLock(LockType): - def release(self) -> None: ... # type: ignore[override] +class RLock(LockType): + def release(self) -> None: ... # type: ignore[override] def interrupt_main() -> None: ... diff --git a/stdlib/_imp.pyi b/stdlib/_imp.pyi index 856188dfbcd2..2b54a0f6fb42 100644 --- a/stdlib/_imp.pyi +++ b/stdlib/_imp.pyi @@ -4,10 +4,9 @@ from _typeshed import ReadableBuffer from importlib.machinery import ModuleSpec from typing import Any -if sys.version_info >= (3, 7): - check_hash_based_pycs: str - def source_hash(key: int, source: ReadableBuffer) -> bytes: ... +check_hash_based_pycs: str +def source_hash(key: int, source: ReadableBuffer) -> bytes: ... def create_builtin(__spec: ModuleSpec) -> types.ModuleType: ... def create_dynamic(__spec: ModuleSpec, __file: Any = ...) -> types.ModuleType: ... def acquire_lock() -> None: ... diff --git a/stdlib/_pydecimal.pyi b/stdlib/_pydecimal.pyi index 0d639bc164d4..faff626ac0ba 100644 --- a/stdlib/_pydecimal.pyi +++ b/stdlib/_pydecimal.pyi @@ -1,5 +1,3 @@ -import sys - # This is a slight lie, the implementations aren't exactly identical # However, in all likelihood, the differences are inconsequential from _decimal import * @@ -41,7 +39,5 @@ __all__ = [ "MIN_EMIN", "MIN_ETINY", "HAVE_THREADS", + "HAVE_CONTEXTVAR", ] - -if sys.version_info >= (3, 7): - __all__ += ["HAVE_CONTEXTVAR"] diff --git a/stdlib/_socket.pyi b/stdlib/_socket.pyi index 7af5be43c234..09dbaae3dc64 100644 --- a/stdlib/_socket.pyi +++ b/stdlib/_socket.pyi @@ -176,8 +176,7 @@ MSG_CTRUNC: int MSG_DONTROUTE: int if sys.platform != "darwin": - if sys.platform != "win32" or sys.version_info >= (3, 7): - MSG_ERRQUEUE: int + MSG_ERRQUEUE: int MSG_OOB: int MSG_PEEK: int @@ -218,15 +217,14 @@ if sys.platform == "linux" and sys.version_info >= (3, 11): SO_INCOMING_CPU: int TCP_FASTOPEN: int TCP_KEEPCNT: int +TCP_KEEPINTVL: int -if sys.platform != "win32" or sys.version_info >= (3, 7): - TCP_KEEPINTVL: int - if sys.platform != "darwin": - TCP_KEEPIDLE: int +if sys.platform != "darwin": + TCP_KEEPIDLE: int TCP_MAXSEG: int TCP_NODELAY: int -if sys.version_info >= (3, 7) and sys.platform != "win32": +if sys.platform != "win32": TCP_NOTSENT_LOWAT: int if sys.version_info >= (3, 10) and sys.platform == "darwin": TCP_KEEPALIVE: int @@ -368,7 +366,7 @@ if sys.platform == "linux" and sys.version_info >= (3, 8): CAN_BCM_RX_RTR_FRAME: int CAN_BCM_CAN_FD_FRAME: int -if sys.platform == "linux" and sys.version_info >= (3, 7): +if sys.platform == "linux": CAN_ISOTP: int if sys.platform == "linux" and sys.version_info >= (3, 9): @@ -491,7 +489,7 @@ if sys.platform == "linux": ALG_SET_OP: int ALG_SET_PUBKEY: int -if sys.platform == "linux" and sys.version_info >= (3, 7): +if sys.platform == "linux": AF_VSOCK: int IOCTL_VM_SOCKETS_GET_LOCAL_CID: int VMADDR_CID_ANY: int @@ -598,9 +596,7 @@ class socket: def getsockopt(self, __level: int, __optname: int) -> int: ... @overload def getsockopt(self, __level: int, __optname: int, __buflen: int) -> bytes: ... - if sys.version_info >= (3, 7): - def getblocking(self) -> bool: ... - + def getblocking(self) -> bool: ... def gettimeout(self) -> float | None: ... if sys.platform == "win32": def ioctl(self, __control: int, __option: int | tuple[int, int, int] | bool) -> None: ... @@ -650,9 +646,7 @@ SocketType = socket # ----- Functions ----- -if sys.version_info >= (3, 7): - def close(__fd: _FD) -> None: ... - +def close(__fd: _FD) -> None: ... def dup(__fd: _FD) -> int: ... # the 5th tuple item is an address diff --git a/stdlib/_winapi.pyi b/stdlib/_winapi.pyi index 77e7714454e7..1c0932667ada 100644 --- a/stdlib/_winapi.pyi +++ b/stdlib/_winapi.pyi @@ -4,16 +4,14 @@ from typing import Any, NoReturn, overload from typing_extensions import Literal, final if sys.platform == "win32": - if sys.version_info >= (3, 7): - ABOVE_NORMAL_PRIORITY_CLASS: Literal[32768] - BELOW_NORMAL_PRIORITY_CLASS: Literal[16384] - CREATE_BREAKAWAY_FROM_JOB: Literal[16777216] - CREATE_DEFAULT_ERROR_MODE: Literal[67108864] - CREATE_NO_WINDOW: Literal[134217728] + ABOVE_NORMAL_PRIORITY_CLASS: Literal[32768] + BELOW_NORMAL_PRIORITY_CLASS: Literal[16384] + CREATE_BREAKAWAY_FROM_JOB: Literal[16777216] + CREATE_DEFAULT_ERROR_MODE: Literal[67108864] + CREATE_NO_WINDOW: Literal[134217728] CREATE_NEW_CONSOLE: Literal[16] CREATE_NEW_PROCESS_GROUP: Literal[512] - if sys.version_info >= (3, 7): - DETACHED_PROCESS: Literal[8] + DETACHED_PROCESS: Literal[8] DUPLICATE_CLOSE_SOURCE: Literal[1] DUPLICATE_SAME_ACCESS: Literal[2] @@ -39,24 +37,21 @@ if sys.platform == "win32": FILE_MAP_EXECUTE: Literal[32] FILE_MAP_READ: Literal[4] FILE_MAP_WRITE: Literal[2] - if sys.version_info >= (3, 7): - FILE_TYPE_CHAR: Literal[2] - FILE_TYPE_DISK: Literal[1] - FILE_TYPE_PIPE: Literal[3] - FILE_TYPE_REMOTE: Literal[32768] - FILE_TYPE_UNKNOWN: Literal[0] + FILE_TYPE_CHAR: Literal[2] + FILE_TYPE_DISK: Literal[1] + FILE_TYPE_PIPE: Literal[3] + FILE_TYPE_REMOTE: Literal[32768] + FILE_TYPE_UNKNOWN: Literal[0] GENERIC_READ: Literal[2147483648] GENERIC_WRITE: Literal[1073741824] - if sys.version_info >= (3, 7): - HIGH_PRIORITY_CLASS: Literal[128] + HIGH_PRIORITY_CLASS: Literal[128] INFINITE: Literal[4294967295] if sys.version_info >= (3, 8): INVALID_HANDLE_VALUE: int # very large number - if sys.version_info >= (3, 7): - IDLE_PRIORITY_CLASS: Literal[64] - NORMAL_PRIORITY_CLASS: Literal[32] - REALTIME_PRIORITY_CLASS: Literal[256] + IDLE_PRIORITY_CLASS: Literal[64] + NORMAL_PRIORITY_CLASS: Literal[32] + REALTIME_PRIORITY_CLASS: Literal[256] NMPWAIT_WAIT_FOREVER: Literal[4294967295] if sys.version_info >= (3, 8): @@ -158,10 +153,8 @@ if sys.platform == "win32": __options: int = ..., ) -> int: ... def ExitProcess(__ExitCode: int) -> NoReturn: ... - if sys.version_info >= (3, 7): - def GetACP() -> int: ... - def GetFileType(handle: int) -> int: ... - + def GetACP() -> int: ... + def GetFileType(handle: int) -> int: ... def GetCurrentProcess() -> int: ... def GetExitCodeProcess(__process: int) -> int: ... def GetLastError() -> int: ... diff --git a/stdlib/argparse.pyi b/stdlib/argparse.pyi index 4f6cb6720988..fbe5de52db46 100644 --- a/stdlib/argparse.pyi +++ b/stdlib/argparse.pyi @@ -171,65 +171,35 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): def parse_args(self, *, namespace: None) -> Namespace: ... # type: ignore[misc] @overload def parse_args(self, *, namespace: _N) -> _N: ... - if sys.version_info >= (3, 7): - @overload - def add_subparsers( - self: _ArgumentParserT, - *, - title: str = ..., - description: str | None = ..., - prog: str = ..., - action: type[Action] = ..., - option_string: str = ..., - dest: str | None = ..., - required: bool = ..., - help: str | None = ..., - metavar: str | None = ..., - ) -> _SubParsersAction[_ArgumentParserT]: ... - @overload - def add_subparsers( - self, - *, - title: str = ..., - description: str | None = ..., - prog: str = ..., - parser_class: type[_ArgumentParserT], - action: type[Action] = ..., - option_string: str = ..., - dest: str | None = ..., - required: bool = ..., - help: str | None = ..., - metavar: str | None = ..., - ) -> _SubParsersAction[_ArgumentParserT]: ... - else: - @overload - def add_subparsers( - self: _ArgumentParserT, - *, - title: str = ..., - description: str | None = ..., - prog: str = ..., - action: type[Action] = ..., - option_string: str = ..., - dest: str | None = ..., - help: str | None = ..., - metavar: str | None = ..., - ) -> _SubParsersAction[_ArgumentParserT]: ... - @overload - def add_subparsers( - self, - *, - title: str = ..., - description: str | None = ..., - prog: str = ..., - parser_class: type[_ArgumentParserT], - action: type[Action] = ..., - option_string: str = ..., - dest: str | None = ..., - help: str | None = ..., - metavar: str | None = ..., - ) -> _SubParsersAction[_ArgumentParserT]: ... - + @overload + def add_subparsers( + self: _ArgumentParserT, + *, + title: str = ..., + description: str | None = ..., + prog: str = ..., + action: type[Action] = ..., + option_string: str = ..., + dest: str | None = ..., + required: bool = ..., + help: str | None = ..., + metavar: str | None = ..., + ) -> _SubParsersAction[_ArgumentParserT]: ... + @overload + def add_subparsers( + self, + *, + title: str = ..., + description: str | None = ..., + prog: str = ..., + parser_class: type[_ArgumentParserT], + action: type[Action] = ..., + option_string: str = ..., + dest: str | None = ..., + required: bool = ..., + help: str | None = ..., + metavar: str | None = ..., + ) -> _SubParsersAction[_ArgumentParserT]: ... def print_usage(self, file: IO[str] | None = ...) -> None: ... def print_help(self, file: IO[str] | None = ...) -> None: ... def format_usage(self) -> str: ... @@ -240,11 +210,10 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): def convert_arg_line_to_args(self, arg_line: str) -> list[str]: ... def exit(self, status: int = ..., message: str | None = ...) -> NoReturn: ... def error(self, message: str) -> NoReturn: ... - if sys.version_info >= (3, 7): - def parse_intermixed_args(self, args: Sequence[str] | None = ..., namespace: Namespace | None = ...) -> Namespace: ... - def parse_known_intermixed_args( - self, args: Sequence[str] | None = ..., namespace: Namespace | None = ... - ) -> tuple[Namespace, list[str]]: ... + def parse_intermixed_args(self, args: Sequence[str] | None = ..., namespace: Namespace | None = ...) -> Namespace: ... + def parse_known_intermixed_args( + self, args: Sequence[str] | None = ..., namespace: Namespace | None = ... + ) -> tuple[Namespace, list[str]]: ... # undocumented def _get_optional_actions(self) -> list[Action]: ... def _get_positional_actions(self) -> list[Action]: ... @@ -478,27 +447,16 @@ class _SubParsersAction(Action, Generic[_ArgumentParserT]): _name_parser_map: dict[str, _ArgumentParserT] choices: dict[str, _ArgumentParserT] _choices_actions: list[Action] - if sys.version_info >= (3, 7): - def __init__( - self, - option_strings: Sequence[str], - prog: str, - parser_class: type[_ArgumentParserT], - dest: str = ..., - required: bool = ..., - help: str | None = ..., - metavar: str | tuple[str, ...] | None = ..., - ) -> None: ... - else: - def __init__( - self, - option_strings: Sequence[str], - prog: str, - parser_class: type[_ArgumentParserT], - dest: str = ..., - help: str | None = ..., - metavar: str | tuple[str, ...] | None = ..., - ) -> None: ... + def __init__( + self, + option_strings: Sequence[str], + prog: str, + parser_class: type[_ArgumentParserT], + dest: str = ..., + required: bool = ..., + help: str | None = ..., + metavar: str | tuple[str, ...] | None = ..., + ) -> None: ... # TODO: Type keyword args properly. def add_parser(self, name: str, **kwargs: Any) -> _ArgumentParserT: ... def _get_subactions(self) -> list[Action]: ... @@ -506,9 +464,5 @@ class _SubParsersAction(Action, Generic[_ArgumentParserT]): # undocumented class ArgumentTypeError(Exception): ... -if sys.version_info < (3, 7): - # undocumented - def _ensure_value(namespace: Namespace, name: str, value: Any) -> Any: ... - # undocumented def _get_action_name(argument: Action | None) -> str | None: ... diff --git a/stdlib/asyncio/__init__.pyi b/stdlib/asyncio/__init__.pyi index 24a86caed66e..4afcd37f5d4a 100644 --- a/stdlib/asyncio/__init__.pyi +++ b/stdlib/asyncio/__init__.pyi @@ -8,14 +8,12 @@ from .futures import * from .locks import * from .protocols import * from .queues import * +from .runners import * from .streams import * from .subprocess import * from .tasks import * from .transports import * -if sys.version_info >= (3, 7): - from .runners import * - if sys.version_info >= (3, 8): from .exceptions import * diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index e413730bc0be..a5105b4f84c1 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -7,19 +7,15 @@ from asyncio.protocols import BaseProtocol from asyncio.tasks import Task from asyncio.transports import BaseTransport, ReadTransport, SubprocessTransport, WriteTransport from collections.abc import Awaitable, Callable, Coroutine, Generator, Iterable, Sequence +from contextvars import Context from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket from typing import IO, Any, TypeVar, overload from typing_extensions import Literal, TypeAlias -if sys.version_info >= (3, 7): - from contextvars import Context - if sys.version_info >= (3, 9): __all__ = ("BaseEventLoop", "Server") -elif sys.version_info >= (3, 7): - __all__ = ("BaseEventLoop",) else: - __all__ = ["BaseEventLoop"] + __all__ = ("BaseEventLoop",) _T = TypeVar("_T") _ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol) @@ -40,7 +36,7 @@ class Server(AbstractServer): ssl_handshake_timeout: float | None, ssl_shutdown_timeout: float | None = ..., ) -> None: ... - elif sys.version_info >= (3, 7): + else: def __init__( self, loop: AbstractEventLoop, @@ -50,21 +46,18 @@ class Server(AbstractServer): backlog: int, ssl_handshake_timeout: float | None, ) -> None: ... - else: - def __init__(self, loop: AbstractEventLoop, sockets: list[socket]) -> None: ... - if sys.version_info >= (3, 7): - def get_loop(self) -> AbstractEventLoop: ... - def is_serving(self) -> bool: ... - async def start_serving(self) -> None: ... - async def serve_forever(self) -> None: ... + + def get_loop(self) -> AbstractEventLoop: ... + def is_serving(self) -> bool: ... + async def start_serving(self) -> None: ... + async def serve_forever(self) -> None: ... if sys.version_info >= (3, 8): @property def sockets(self) -> tuple[socket, ...]: ... - elif sys.version_info >= (3, 7): + else: @property def sockets(self) -> list[socket]: ... - else: - sockets: list[socket] | None + def close(self) -> None: ... async def wait_closed(self) -> None: ... @@ -81,19 +74,11 @@ class BaseEventLoop(AbstractEventLoop): def close(self) -> None: ... async def shutdown_asyncgens(self) -> None: ... # Methods scheduling callbacks. All these return Handles. - if sys.version_info >= (3, 7): - def call_soon(self, callback: Callable[..., Any], *args: Any, context: Context | None = ...) -> Handle: ... - def call_later( - self, delay: float, callback: Callable[..., Any], *args: Any, context: Context | None = ... - ) -> TimerHandle: ... - def call_at( - self, when: float, callback: Callable[..., Any], *args: Any, context: Context | None = ... - ) -> TimerHandle: ... - else: - def call_soon(self, callback: Callable[..., Any], *args: Any) -> Handle: ... - def call_later(self, delay: float, callback: Callable[..., Any], *args: Any) -> TimerHandle: ... - def call_at(self, when: float, callback: Callable[..., Any], *args: Any) -> TimerHandle: ... - + def call_soon(self, callback: Callable[..., Any], *args: Any, context: Context | None = ...) -> Handle: ... + def call_later( + self, delay: float, callback: Callable[..., Any], *args: Any, context: Context | None = ... + ) -> TimerHandle: ... + def call_at(self, when: float, callback: Callable[..., Any], *args: Any, context: Context | None = ...) -> TimerHandle: ... def time(self) -> float: ... # Future methods def create_future(self) -> Future[Any]: ... @@ -110,11 +95,7 @@ class BaseEventLoop(AbstractEventLoop): def set_task_factory(self, factory: _TaskFactory | None) -> None: ... def get_task_factory(self) -> _TaskFactory | None: ... # Methods for interacting with threads - if sys.version_info >= (3, 7): - def call_soon_threadsafe(self, callback: Callable[..., Any], *args: Any, context: Context | None = ...) -> Handle: ... - else: - def call_soon_threadsafe(self, callback: Callable[..., Any], *args: Any) -> Handle: ... - + def call_soon_threadsafe(self, callback: Callable[..., Any], *args: Any, context: Context | None = ...) -> Handle: ... def run_in_executor(self, executor: Any, func: Callable[..., _T], *args: Any) -> Future[_T]: ... def set_default_executor(self, executor: Any) -> None: ... # Network I/O methods returning Futures. @@ -205,7 +186,7 @@ class BaseEventLoop(AbstractEventLoop): happy_eyeballs_delay: float | None = ..., interleave: int | None = ..., ) -> tuple[BaseTransport, _ProtocolT]: ... - elif sys.version_info >= (3, 7): + else: @overload async def create_connection( self, @@ -238,37 +219,6 @@ class BaseEventLoop(AbstractEventLoop): server_hostname: str | None = ..., ssl_handshake_timeout: float | None = ..., ) -> tuple[BaseTransport, _ProtocolT]: ... - else: - @overload - async def create_connection( - self, - protocol_factory: Callable[[], _ProtocolT], - host: str = ..., - port: int = ..., - *, - ssl: _SSLContext = ..., - family: int = ..., - proto: int = ..., - flags: int = ..., - sock: None = ..., - local_addr: tuple[str, int] | None = ..., - server_hostname: str | None = ..., - ) -> tuple[BaseTransport, _ProtocolT]: ... - @overload - async def create_connection( - self, - protocol_factory: Callable[[], _ProtocolT], - host: None = ..., - port: None = ..., - *, - ssl: _SSLContext = ..., - family: int = ..., - proto: int = ..., - flags: int = ..., - sock: socket, - local_addr: None = ..., - server_hostname: str | None = ..., - ) -> tuple[BaseTransport, _ProtocolT]: ... if sys.version_info >= (3, 11): @overload async def create_server( @@ -326,7 +276,7 @@ class BaseEventLoop(AbstractEventLoop): ssl_handshake_timeout: float | None = ..., ssl_shutdown_timeout: float | None = ..., ) -> tuple[BaseTransport, _ProtocolT]: ... - elif sys.version_info >= (3, 7): + else: @overload async def create_server( self, @@ -379,47 +329,13 @@ class BaseEventLoop(AbstractEventLoop): ssl: _SSLContext = ..., ssl_handshake_timeout: float | None = ..., ) -> tuple[BaseTransport, _ProtocolT]: ... - else: - @overload - async def create_server( - self, - protocol_factory: _ProtocolFactory, - host: str | Sequence[str] | None = ..., - port: int = ..., - *, - family: int = ..., - flags: int = ..., - sock: None = ..., - backlog: int = ..., - ssl: _SSLContext = ..., - reuse_address: bool | None = ..., - reuse_port: bool | None = ..., - ) -> Server: ... - @overload - async def create_server( - self, - protocol_factory: _ProtocolFactory, - host: None = ..., - port: None = ..., - *, - family: int = ..., - flags: int = ..., - sock: socket, - backlog: int = ..., - ssl: _SSLContext = ..., - reuse_address: bool | None = ..., - reuse_port: bool | None = ..., - ) -> Server: ... - async def connect_accepted_socket( - self, protocol_factory: Callable[[], _ProtocolT], sock: socket, *, ssl: _SSLContext = ... - ) -> tuple[BaseTransport, _ProtocolT]: ... - if sys.version_info >= (3, 7): - async def sock_sendfile( - self, sock: socket, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool | None = ... - ) -> int: ... - async def sendfile( - self, transport: BaseTransport, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool = ... - ) -> int: ... + + async def sock_sendfile( + self, sock: socket, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool | None = ... + ) -> int: ... + async def sendfile( + self, transport: BaseTransport, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool = ... + ) -> int: ... if sys.version_info >= (3, 11): async def create_datagram_endpoint( # type: ignore[override] self, @@ -493,18 +409,11 @@ class BaseEventLoop(AbstractEventLoop): def remove_writer(self, fd: FileDescriptorLike) -> bool: ... # The sock_* methods (and probably some others) are not actually implemented on # BaseEventLoop, only on subclasses. We list them here for now for convenience. - # Completion based I/O methods returning Futures prior to 3.7 - if sys.version_info >= (3, 7): - async def sock_recv(self, sock: socket, nbytes: int) -> bytes: ... - async def sock_recv_into(self, sock: socket, buf: WriteableBuffer) -> int: ... - async def sock_sendall(self, sock: socket, data: bytes) -> None: ... - async def sock_connect(self, sock: socket, address: _Address) -> None: ... - async def sock_accept(self, sock: socket) -> tuple[socket, _RetAddress]: ... - else: - def sock_recv(self, sock: socket, nbytes: int) -> Future[bytes]: ... - def sock_sendall(self, sock: socket, data: bytes) -> Future[None]: ... - def sock_connect(self, sock: socket, address: _Address) -> Future[None]: ... - def sock_accept(self, sock: socket) -> Future[tuple[socket, _RetAddress]]: ... + async def sock_recv(self, sock: socket, nbytes: int) -> bytes: ... + async def sock_recv_into(self, sock: socket, buf: WriteableBuffer) -> int: ... + async def sock_sendall(self, sock: socket, data: bytes) -> None: ... + async def sock_connect(self, sock: socket, address: _Address) -> None: ... + async def sock_accept(self, sock: socket) -> tuple[socket, _RetAddress]: ... if sys.version_info >= (3, 11): async def sock_recvfrom(self, sock: socket, bufsize: int) -> bytes: ... async def sock_recvfrom_into(self, sock: socket, buf: WriteableBuffer, nbytes: int = ...) -> int: ... diff --git a/stdlib/asyncio/base_futures.pyi b/stdlib/asyncio/base_futures.pyi index 8a973d1618f4..c51174ef23cd 100644 --- a/stdlib/asyncio/base_futures.pyi +++ b/stdlib/asyncio/base_futures.pyi @@ -1,17 +1,11 @@ -import sys from collections.abc import Callable, Sequence +from contextvars import Context from typing import Any from typing_extensions import Literal -if sys.version_info >= (3, 7): - from contextvars import Context - from . import futures -if sys.version_info >= (3, 7): - __all__ = () -else: - __all__: list[str] = [] +__all__ = () # asyncio defines 'isfuture()' in base_futures.py and re-imports it in futures.py # but it leads to circular import error in pytype tool. @@ -22,10 +16,5 @@ _PENDING: Literal["PENDING"] # undocumented _CANCELLED: Literal["CANCELLED"] # undocumented _FINISHED: Literal["FINISHED"] # undocumented -if sys.version_info >= (3, 7): - def _format_callbacks(cb: Sequence[tuple[Callable[[futures.Future[Any]], None], Context]]) -> str: ... # undocumented - -else: - def _format_callbacks(cb: Sequence[Callable[[futures.Future[Any]], None]]) -> str: ... # undocumented - +def _format_callbacks(cb: Sequence[tuple[Callable[[futures.Future[Any]], None], Context]]) -> str: ... # undocumented def _future_repr_info(future: futures.Future[Any]) -> list[str]: ... # undocumented diff --git a/stdlib/asyncio/constants.pyi b/stdlib/asyncio/constants.pyi index 1fa643c7414b..af209fa9ee62 100644 --- a/stdlib/asyncio/constants.pyi +++ b/stdlib/asyncio/constants.pyi @@ -5,9 +5,8 @@ from typing_extensions import Literal LOG_THRESHOLD_FOR_CONNLOST_WRITES: Literal[5] ACCEPT_RETRY_DELAY: Literal[1] DEBUG_STACK_DEPTH: Literal[10] -if sys.version_info >= (3, 7): - SSL_HANDSHAKE_TIMEOUT: float - SENDFILE_FALLBACK_READBUFFER_SIZE: Literal[262144] +SSL_HANDSHAKE_TIMEOUT: float +SENDFILE_FALLBACK_READBUFFER_SIZE: Literal[262144] if sys.version_info >= (3, 11): SSL_SHUTDOWN_TIMEOUT: float FLOW_CONTROL_HIGH_WATER_SSL_READ: Literal[256] diff --git a/stdlib/asyncio/coroutines.pyi b/stdlib/asyncio/coroutines.pyi index 5c640af5a1ca..38f2bffd5c2b 100644 --- a/stdlib/asyncio/coroutines.pyi +++ b/stdlib/asyncio/coroutines.pyi @@ -5,10 +5,8 @@ from typing_extensions import TypeGuard if sys.version_info >= (3, 11): __all__ = ("iscoroutinefunction", "iscoroutine") -elif sys.version_info >= (3, 7): - __all__ = ("coroutine", "iscoroutinefunction", "iscoroutine") else: - __all__ = ["coroutine", "iscoroutinefunction", "iscoroutine"] + __all__ = ("coroutine", "iscoroutinefunction", "iscoroutine") if sys.version_info < (3, 11): from collections.abc import Callable diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index fb4dac56f01e..066ba084ae34 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -3,6 +3,7 @@ import sys from _typeshed import FileDescriptorLike, Self, WriteableBuffer from abc import ABCMeta, abstractmethod from collections.abc import Awaitable, Callable, Coroutine, Generator, Sequence +from contextvars import Context from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket from typing import IO, Any, Protocol, TypeVar, overload from typing_extensions import Literal, TypeAlias @@ -14,9 +15,6 @@ from .tasks import Task from .transports import BaseTransport, ReadTransport, SubprocessTransport, WriteTransport from .unix_events import AbstractChildWatcher -if sys.version_info >= (3, 7): - from contextvars import Context - if sys.version_info >= (3, 8): __all__ = ( "AbstractEventLoopPolicy", @@ -36,7 +34,7 @@ if sys.version_info >= (3, 8): "_get_running_loop", ) -elif sys.version_info >= (3, 7): +else: __all__ = ( "AbstractEventLoopPolicy", "AbstractEventLoop", @@ -56,24 +54,6 @@ elif sys.version_info >= (3, 7): "_get_running_loop", ) -else: - __all__ = [ - "AbstractEventLoopPolicy", - "AbstractEventLoop", - "AbstractServer", - "Handle", - "TimerHandle", - "get_event_loop_policy", - "set_event_loop_policy", - "get_event_loop", - "set_event_loop", - "new_event_loop", - "get_child_watcher", - "set_child_watcher", - "_set_running_loop", - "_get_running_loop", - ] - _T = TypeVar("_T") _ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol) _Context: TypeAlias = dict[str, Any] @@ -89,35 +69,24 @@ class _TaskFactory(Protocol): class Handle: _cancelled: bool _args: Sequence[Any] - if sys.version_info >= (3, 7): - def __init__( - self, callback: Callable[..., Any], args: Sequence[Any], loop: AbstractEventLoop, context: Context | None = ... - ) -> None: ... - else: - def __init__(self, callback: Callable[..., Any], args: Sequence[Any], loop: AbstractEventLoop) -> None: ... - + def __init__( + self, callback: Callable[..., Any], args: Sequence[Any], loop: AbstractEventLoop, context: Context | None = ... + ) -> None: ... def cancel(self) -> None: ... def _run(self) -> None: ... - if sys.version_info >= (3, 7): - def cancelled(self) -> bool: ... + def cancelled(self) -> bool: ... class TimerHandle(Handle): - if sys.version_info >= (3, 7): - def __init__( - self, - when: float, - callback: Callable[..., Any], - args: Sequence[Any], - loop: AbstractEventLoop, - context: Context | None = ..., - ) -> None: ... - else: - def __init__(self, when: float, callback: Callable[..., Any], args: Sequence[Any], loop: AbstractEventLoop) -> None: ... - + def __init__( + self, + when: float, + callback: Callable[..., Any], + args: Sequence[Any], + loop: AbstractEventLoop, + context: Context | None = ..., + ) -> None: ... def __hash__(self) -> int: ... - if sys.version_info >= (3, 7): - def when(self) -> float: ... - + def when(self) -> float: ... def __lt__(self, other: TimerHandle) -> bool: ... def __le__(self, other: TimerHandle) -> bool: ... def __gt__(self, other: TimerHandle) -> bool: ... @@ -127,18 +96,16 @@ class TimerHandle(Handle): class AbstractServer: @abstractmethod def close(self) -> None: ... - if sys.version_info >= (3, 7): - async def __aenter__(self: Self) -> Self: ... - async def __aexit__(self, *exc: object) -> None: ... - @abstractmethod - def get_loop(self) -> AbstractEventLoop: ... - @abstractmethod - def is_serving(self) -> bool: ... - @abstractmethod - async def start_serving(self) -> None: ... - @abstractmethod - async def serve_forever(self) -> None: ... - + async def __aenter__(self: Self) -> Self: ... + async def __aexit__(self, *exc: object) -> None: ... + @abstractmethod + def get_loop(self) -> AbstractEventLoop: ... + @abstractmethod + def is_serving(self) -> bool: ... + @abstractmethod + async def start_serving(self) -> None: ... + @abstractmethod + async def serve_forever(self) -> None: ... @abstractmethod async def wait_closed(self) -> None: ... @@ -317,7 +284,7 @@ class AbstractEventLoop: happy_eyeballs_delay: float | None = ..., interleave: int | None = ..., ) -> tuple[BaseTransport, _ProtocolT]: ... - elif sys.version_info >= (3, 7): + else: @overload @abstractmethod async def create_connection( @@ -352,39 +319,6 @@ class AbstractEventLoop: server_hostname: str | None = ..., ssl_handshake_timeout: float | None = ..., ) -> tuple[BaseTransport, _ProtocolT]: ... - else: - @overload - @abstractmethod - async def create_connection( - self, - protocol_factory: Callable[[], _ProtocolT], - host: str = ..., - port: int = ..., - *, - ssl: _SSLContext = ..., - family: int = ..., - proto: int = ..., - flags: int = ..., - sock: None = ..., - local_addr: tuple[str, int] | None = ..., - server_hostname: str | None = ..., - ) -> tuple[BaseTransport, _ProtocolT]: ... - @overload - @abstractmethod - async def create_connection( - self, - protocol_factory: Callable[[], _ProtocolT], - host: None = ..., - port: None = ..., - *, - ssl: _SSLContext = ..., - family: int = ..., - proto: int = ..., - flags: int = ..., - sock: socket, - local_addr: None = ..., - server_hostname: str | None = ..., - ) -> tuple[BaseTransport, _ProtocolT]: ... if sys.version_info >= (3, 11): @overload @abstractmethod @@ -448,7 +382,7 @@ class AbstractEventLoop: ssl_shutdown_timeout: float | None = ..., start_serving: bool = ..., ) -> Server: ... - elif sys.version_info >= (3, 7): + else: @overload @abstractmethod async def create_server( @@ -507,48 +441,6 @@ class AbstractEventLoop: ssl_handshake_timeout: float | None = ..., start_serving: bool = ..., ) -> Server: ... - else: - @overload - @abstractmethod - async def create_server( - self, - protocol_factory: _ProtocolFactory, - host: str | Sequence[str] | None = ..., - port: int = ..., - *, - family: int = ..., - flags: int = ..., - sock: None = ..., - backlog: int = ..., - ssl: _SSLContext = ..., - reuse_address: bool | None = ..., - reuse_port: bool | None = ..., - ) -> Server: ... - @overload - @abstractmethod - async def create_server( - self, - protocol_factory: _ProtocolFactory, - host: None = ..., - port: None = ..., - *, - family: int = ..., - flags: int = ..., - sock: socket, - backlog: int = ..., - ssl: _SSLContext = ..., - reuse_address: bool | None = ..., - reuse_port: bool | None = ..., - ) -> Server: ... - async def create_unix_server( - self, - protocol_factory: _ProtocolFactory, - path: str, - *, - sock: socket | None = ..., - backlog: int = ..., - ssl: _SSLContext = ..., - ) -> Server: ... if sys.version_info >= (3, 11): async def connect_accepted_socket( self, @@ -580,7 +472,7 @@ class AbstractEventLoop: ssl_handshake_timeout: float | None = ..., ssl_shutdown_timeout: float | None = ..., ) -> tuple[BaseTransport, _ProtocolT]: ... - elif sys.version_info >= (3, 7): + else: async def create_unix_connection( self, protocol_factory: Callable[[], _ProtocolT], @@ -591,26 +483,15 @@ class AbstractEventLoop: server_hostname: str | None = ..., ssl_handshake_timeout: float | None = ..., ) -> tuple[BaseTransport, _ProtocolT]: ... - else: - async def create_unix_connection( - self, - protocol_factory: Callable[[], _ProtocolT], - path: str, - *, - ssl: _SSLContext = ..., - sock: socket | None = ..., - server_hostname: str | None = ..., - ) -> tuple[BaseTransport, _ProtocolT]: ... - if sys.version_info >= (3, 7): - @abstractmethod - async def sock_sendfile( - self, sock: socket, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool | None = ... - ) -> int: ... - @abstractmethod - async def sendfile( - self, transport: BaseTransport, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool = ... - ) -> int: ... + @abstractmethod + async def sock_sendfile( + self, sock: socket, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool | None = ... + ) -> int: ... + @abstractmethod + async def sendfile( + self, transport: BaseTransport, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool = ... + ) -> int: ... @abstractmethod async def create_datagram_endpoint( self, @@ -677,26 +558,16 @@ class AbstractEventLoop: @abstractmethod def remove_writer(self, fd: FileDescriptorLike) -> bool: ... # Completion based I/O methods returning Futures prior to 3.7 - if sys.version_info >= (3, 7): - @abstractmethod - async def sock_recv(self, sock: socket, nbytes: int) -> bytes: ... - @abstractmethod - async def sock_recv_into(self, sock: socket, buf: WriteableBuffer) -> int: ... - @abstractmethod - async def sock_sendall(self, sock: socket, data: bytes) -> None: ... - @abstractmethod - async def sock_connect(self, sock: socket, address: _Address) -> None: ... - @abstractmethod - async def sock_accept(self, sock: socket) -> tuple[socket, _RetAddress]: ... - else: - @abstractmethod - def sock_recv(self, sock: socket, nbytes: int) -> Future[bytes]: ... - @abstractmethod - def sock_sendall(self, sock: socket, data: bytes) -> Future[None]: ... - @abstractmethod - def sock_connect(self, sock: socket, address: _Address) -> Future[None]: ... - @abstractmethod - def sock_accept(self, sock: socket) -> Future[tuple[socket, _RetAddress]]: ... + @abstractmethod + async def sock_recv(self, sock: socket, nbytes: int) -> bytes: ... + @abstractmethod + async def sock_recv_into(self, sock: socket, buf: WriteableBuffer) -> int: ... + @abstractmethod + async def sock_sendall(self, sock: socket, data: bytes) -> None: ... + @abstractmethod + async def sock_connect(self, sock: socket, address: _Address) -> None: ... + @abstractmethod + async def sock_accept(self, sock: socket) -> tuple[socket, _RetAddress]: ... if sys.version_info >= (3, 11): @abstractmethod async def sock_recvfrom(self, sock: socket, bufsize: int) -> bytes: ... @@ -755,8 +626,7 @@ def get_child_watcher() -> AbstractChildWatcher: ... def set_child_watcher(watcher: AbstractChildWatcher) -> None: ... def _set_running_loop(__loop: AbstractEventLoop | None) -> None: ... def _get_running_loop() -> AbstractEventLoop: ... +def get_running_loop() -> AbstractEventLoop: ... -if sys.version_info >= (3, 7): - def get_running_loop() -> AbstractEventLoop: ... - if sys.version_info < (3, 8): - class SendfileNotAvailableError(RuntimeError): ... +if sys.version_info < (3, 8): + class SendfileNotAvailableError(RuntimeError): ... diff --git a/stdlib/asyncio/futures.pyi b/stdlib/asyncio/futures.pyi index 21bfe86e44c6..96b5cb925099 100644 --- a/stdlib/asyncio/futures.pyi +++ b/stdlib/asyncio/futures.pyi @@ -12,18 +12,15 @@ if sys.version_info < (3, 8): class InvalidStateError(Error): ... -if sys.version_info >= (3, 7): - from contextvars import Context +from contextvars import Context if sys.version_info >= (3, 9): from types import GenericAlias if sys.version_info >= (3, 8): __all__ = ("Future", "wrap_future", "isfuture") -elif sys.version_info >= (3, 7): - __all__ = ("CancelledError", "TimeoutError", "InvalidStateError", "Future", "wrap_future", "isfuture") else: - __all__ = ["CancelledError", "TimeoutError", "InvalidStateError", "Future", "wrap_future", "isfuture"] + __all__ = ("CancelledError", "TimeoutError", "InvalidStateError", "Future", "wrap_future", "isfuture") _T = TypeVar("_T") @@ -32,15 +29,6 @@ _T = TypeVar("_T") # That's why the import order is reversed. def isfuture(obj: object) -> TypeGuard[Future[Any]]: ... -if sys.version_info < (3, 7): - class _TracebackLogger: - exc: BaseException - tb: list[str] - def __init__(self, exc: Any, loop: AbstractEventLoop) -> None: ... - def activate(self) -> None: ... - def clear(self) -> None: ... - def __del__(self) -> None: ... - class Future(Awaitable[_T], Iterable[_T]): _state: str @property @@ -53,15 +41,10 @@ class Future(Awaitable[_T], Iterable[_T]): _asyncio_future_blocking: bool # is a part of duck-typing contract for `Future` def __init__(self, *, loop: AbstractEventLoop | None = ...) -> None: ... def __del__(self) -> None: ... - if sys.version_info >= (3, 7): - def get_loop(self) -> AbstractEventLoop: ... - @property - def _callbacks(self: Self) -> list[tuple[Callable[[Self], Any], Context]]: ... - def add_done_callback(self: Self, __fn: Callable[[Self], Any], *, context: Context | None = ...) -> None: ... - else: - @property - def _callbacks(self: Self) -> list[Callable[[Self], Any]]: ... - def add_done_callback(self: Self, __fn: Callable[[Self], Any]) -> None: ... + def get_loop(self) -> AbstractEventLoop: ... + @property + def _callbacks(self: Self) -> list[tuple[Callable[[Self], Any], Context]]: ... + def add_done_callback(self: Self, __fn: Callable[[Self], Any], *, context: Context | None = ...) -> None: ... if sys.version_info >= (3, 9): def cancel(self, msg: Any | None = ...) -> bool: ... else: diff --git a/stdlib/asyncio/locks.pyi b/stdlib/asyncio/locks.pyi index 269602c7bc66..61f8a81dedc7 100644 --- a/stdlib/asyncio/locks.pyi +++ b/stdlib/asyncio/locks.pyi @@ -15,10 +15,8 @@ if sys.version_info >= (3, 11): if sys.version_info >= (3, 11): __all__ = ("Lock", "Event", "Condition", "Semaphore", "BoundedSemaphore", "Barrier") -elif sys.version_info >= (3, 7): - __all__ = ("Lock", "Event", "Condition", "Semaphore", "BoundedSemaphore") else: - __all__ = ["Lock", "Event", "Condition", "Semaphore", "BoundedSemaphore"] + __all__ = ("Lock", "Event", "Condition", "Semaphore", "BoundedSemaphore") _T = TypeVar("_T") diff --git a/stdlib/asyncio/proactor_events.pyi b/stdlib/asyncio/proactor_events.pyi index 21247401c9ba..f8520cb2b912 100644 --- a/stdlib/asyncio/proactor_events.pyi +++ b/stdlib/asyncio/proactor_events.pyi @@ -6,10 +6,7 @@ from typing_extensions import Literal from . import base_events, constants, events, futures, streams, transports -if sys.version_info >= (3, 7): - __all__ = ("BaseProactorEventLoop",) -else: - __all__ = ["BaseProactorEventLoop"] +__all__ = ("BaseProactorEventLoop",) if sys.version_info >= (3, 8): class _WarnCallbackProtocol(Protocol): diff --git a/stdlib/asyncio/protocols.pyi b/stdlib/asyncio/protocols.pyi index e2fc118947bc..5173b74ed5a0 100644 --- a/stdlib/asyncio/protocols.pyi +++ b/stdlib/asyncio/protocols.pyi @@ -1,12 +1,8 @@ -import sys from _typeshed import ReadableBuffer from asyncio import transports from typing import Any -if sys.version_info >= (3, 7): - __all__ = ("BaseProtocol", "Protocol", "DatagramProtocol", "SubprocessProtocol", "BufferedProtocol") -else: - __all__ = ["BaseProtocol", "Protocol", "DatagramProtocol", "SubprocessProtocol"] +__all__ = ("BaseProtocol", "Protocol", "DatagramProtocol", "SubprocessProtocol", "BufferedProtocol") class BaseProtocol: def connection_made(self, transport: transports.BaseTransport) -> None: ... @@ -18,11 +14,10 @@ class Protocol(BaseProtocol): def data_received(self, data: bytes) -> None: ... def eof_received(self) -> bool | None: ... -if sys.version_info >= (3, 7): - class BufferedProtocol(BaseProtocol): - def get_buffer(self, sizehint: int) -> ReadableBuffer: ... - def buffer_updated(self, nbytes: int) -> None: ... - def eof_received(self) -> bool | None: ... +class BufferedProtocol(BaseProtocol): + def get_buffer(self, sizehint: int) -> ReadableBuffer: ... + def buffer_updated(self, nbytes: int) -> None: ... + def eof_received(self) -> bool | None: ... class DatagramProtocol(BaseProtocol): def connection_made(self, transport: transports.DatagramTransport) -> None: ... # type: ignore[override] diff --git a/stdlib/asyncio/queues.pyi b/stdlib/asyncio/queues.pyi index 0e1a0b2808df..90ba39aebb96 100644 --- a/stdlib/asyncio/queues.pyi +++ b/stdlib/asyncio/queues.pyi @@ -5,10 +5,7 @@ from typing import Any, Generic, TypeVar if sys.version_info >= (3, 9): from types import GenericAlias -if sys.version_info >= (3, 7): - __all__ = ("Queue", "PriorityQueue", "LifoQueue", "QueueFull", "QueueEmpty") -else: - __all__ = ["Queue", "PriorityQueue", "LifoQueue", "QueueFull", "QueueEmpty"] +__all__ = ("Queue", "PriorityQueue", "LifoQueue", "QueueFull", "QueueEmpty") class QueueEmpty(Exception): ... class QueueFull(Exception): ... diff --git a/stdlib/asyncio/selector_events.pyi b/stdlib/asyncio/selector_events.pyi index 698bfef351a1..c5468d4d72c7 100644 --- a/stdlib/asyncio/selector_events.pyi +++ b/stdlib/asyncio/selector_events.pyi @@ -1,12 +1,8 @@ import selectors -import sys from . import base_events -if sys.version_info >= (3, 7): - __all__ = ("BaseSelectorEventLoop",) -else: - __all__ = ["BaseSelectorEventLoop"] +__all__ = ("BaseSelectorEventLoop",) class BaseSelectorEventLoop(base_events.BaseEventLoop): def __init__(self, selector: selectors.BaseSelector | None = ...) -> None: ... diff --git a/stdlib/asyncio/sslproto.pyi b/stdlib/asyncio/sslproto.pyi index 1d3d6d7c83ec..bfb358da65ff 100644 --- a/stdlib/asyncio/sslproto.pyi +++ b/stdlib/asyncio/sslproto.pyi @@ -76,17 +76,13 @@ class _SSLProtocolTransport(transports._FlowControlMixin, transports.Transport): def get_protocol(self) -> protocols.BaseProtocol: ... def is_closing(self) -> bool: ... def close(self) -> None: ... - if sys.version_info >= (3, 7): - def is_reading(self) -> bool: ... - + def is_reading(self) -> bool: ... def pause_reading(self) -> None: ... def resume_reading(self) -> None: ... def set_write_buffer_limits(self, high: int | None = ..., low: int | None = ...) -> None: ... def get_write_buffer_size(self) -> int: ... - if sys.version_info >= (3, 7): - @property - def _protocol_paused(self) -> bool: ... - + @property + def _protocol_paused(self) -> bool: ... def write(self, data: bytes) -> None: ... def can_write_eof(self) -> Literal[False]: ... def abort(self) -> None: ... @@ -138,18 +134,6 @@ class SSLProtocol(_SSLProtocolBase): ssl_handshake_timeout: int | None = ..., ssl_shutdown_timeout: float | None = ..., ) -> None: ... - elif sys.version_info >= (3, 7): - def __init__( - self, - loop: events.AbstractEventLoop, - app_protocol: protocols.BaseProtocol, - sslcontext: ssl.SSLContext, - waiter: futures.Future[Any], - server_side: bool = ..., - server_hostname: str | None = ..., - call_connection_made: bool = ..., - ssl_handshake_timeout: int | None = ..., - ) -> None: ... else: def __init__( self, @@ -160,10 +144,10 @@ class SSLProtocol(_SSLProtocolBase): server_side: bool = ..., server_hostname: str | None = ..., call_connection_made: bool = ..., + ssl_handshake_timeout: int | None = ..., ) -> None: ... - if sys.version_info >= (3, 7): - def _set_app_protocol(self, app_protocol: protocols.BaseProtocol) -> None: ... + def _set_app_protocol(self, app_protocol: protocols.BaseProtocol) -> None: ... def _wakeup_waiter(self, exc: BaseException | None = ...) -> None: ... def connection_made(self, transport: transports.BaseTransport) -> None: ... def connection_lost(self, exc: BaseException | None) -> None: ... @@ -178,9 +162,7 @@ class SSLProtocol(_SSLProtocolBase): def _write_appdata(self, data: bytes) -> None: ... def _start_handshake(self) -> None: ... - if sys.version_info >= (3, 7): - def _check_handshake_timeout(self) -> None: ... - + def _check_handshake_timeout(self) -> None: ... def _on_handshake_complete(self, handshake_exc: BaseException | None) -> None: ... def _fatal_error(self, exc: BaseException, message: str = ...) -> None: ... def _abort(self) -> None: ... diff --git a/stdlib/asyncio/streams.pyi b/stdlib/asyncio/streams.pyi index 0f24d01d50cf..5bf2d3620dbe 100644 --- a/stdlib/asyncio/streams.pyi +++ b/stdlib/asyncio/streams.pyi @@ -11,7 +11,7 @@ from .base_events import Server if sys.platform == "win32": if sys.version_info >= (3, 8): __all__ = ("StreamReader", "StreamWriter", "StreamReaderProtocol", "open_connection", "start_server") - elif sys.version_info >= (3, 7): + else: __all__ = ( "StreamReader", "StreamWriter", @@ -21,16 +21,6 @@ if sys.platform == "win32": "IncompleteReadError", "LimitOverrunError", ) - else: - __all__ = [ - "StreamReader", - "StreamWriter", - "StreamReaderProtocol", - "open_connection", - "start_server", - "IncompleteReadError", - "LimitOverrunError", - ] else: if sys.version_info >= (3, 8): __all__ = ( @@ -42,7 +32,7 @@ else: "open_unix_connection", "start_unix_server", ) - elif sys.version_info >= (3, 7): + else: __all__ = ( "StreamReader", "StreamWriter", @@ -54,18 +44,6 @@ else: "open_unix_connection", "start_unix_server", ) - else: - __all__ = [ - "StreamReader", - "StreamWriter", - "StreamReaderProtocol", - "open_connection", - "start_server", - "IncompleteReadError", - "LimitOverrunError", - "open_unix_connection", - "start_unix_server", - ] _ClientConnectedCallback: TypeAlias = Callable[[StreamReader, StreamWriter], Awaitable[None] | None] @@ -120,24 +98,20 @@ else: ) -> Server: ... if sys.platform != "win32": - if sys.version_info >= (3, 7): - _PathType: TypeAlias = StrPath - else: - _PathType: TypeAlias = str if sys.version_info >= (3, 10): async def open_unix_connection( - path: _PathType | None = ..., *, limit: int = ..., **kwds: Any + path: StrPath | None = ..., *, limit: int = ..., **kwds: Any ) -> tuple[StreamReader, StreamWriter]: ... async def start_unix_server( - client_connected_cb: _ClientConnectedCallback, path: _PathType | None = ..., *, limit: int = ..., **kwds: Any + client_connected_cb: _ClientConnectedCallback, path: StrPath | None = ..., *, limit: int = ..., **kwds: Any ) -> Server: ... else: async def open_unix_connection( - path: _PathType | None = ..., *, loop: events.AbstractEventLoop | None = ..., limit: int = ..., **kwds: Any + path: StrPath | None = ..., *, loop: events.AbstractEventLoop | None = ..., limit: int = ..., **kwds: Any ) -> tuple[StreamReader, StreamWriter]: ... async def start_unix_server( client_connected_cb: _ClientConnectedCallback, - path: _PathType | None = ..., + path: StrPath | None = ..., *, loop: events.AbstractEventLoop | None = ..., limit: int = ..., @@ -174,10 +148,8 @@ class StreamWriter: def write_eof(self) -> None: ... def can_write_eof(self) -> bool: ... def close(self) -> None: ... - if sys.version_info >= (3, 7): - def is_closing(self) -> bool: ... - async def wait_closed(self) -> None: ... - + def is_closing(self) -> bool: ... + async def wait_closed(self) -> None: ... def get_extra_info(self, name: str, default: Any = ...) -> Any: ... async def drain(self) -> None: ... if sys.version_info >= (3, 11): diff --git a/stdlib/asyncio/subprocess.pyi b/stdlib/asyncio/subprocess.pyi index 55093a3ebd9f..5b62c20bd07f 100644 --- a/stdlib/asyncio/subprocess.pyi +++ b/stdlib/asyncio/subprocess.pyi @@ -6,10 +6,7 @@ from collections.abc import Callable from typing import IO, Any from typing_extensions import Literal, TypeAlias -if sys.version_info >= (3, 7): - __all__ = ("create_subprocess_exec", "create_subprocess_shell") -else: - __all__ = ["create_subprocess_exec", "create_subprocess_shell"] +__all__ = ("create_subprocess_exec", "create_subprocess_shell") if sys.version_info >= (3, 8): _ExecArg: TypeAlias = StrOrBytesPath diff --git a/stdlib/asyncio/tasks.pyi b/stdlib/asyncio/tasks.pyi index 8442090f11ea..a047998c07c4 100644 --- a/stdlib/asyncio/tasks.pyi +++ b/stdlib/asyncio/tasks.pyi @@ -13,43 +13,27 @@ if sys.version_info >= (3, 9): if sys.version_info >= (3, 11): from contextvars import Context -if sys.version_info >= (3, 7): - __all__ = ( - "Task", - "create_task", - "FIRST_COMPLETED", - "FIRST_EXCEPTION", - "ALL_COMPLETED", - "wait", - "wait_for", - "as_completed", - "sleep", - "gather", - "shield", - "ensure_future", - "run_coroutine_threadsafe", - "current_task", - "all_tasks", - "_register_task", - "_unregister_task", - "_enter_task", - "_leave_task", - ) -else: - __all__ = [ - "Task", - "FIRST_COMPLETED", - "FIRST_EXCEPTION", - "ALL_COMPLETED", - "wait", - "wait_for", - "as_completed", - "sleep", - "gather", - "shield", - "ensure_future", - "run_coroutine_threadsafe", - ] +__all__ = ( + "Task", + "create_task", + "FIRST_COMPLETED", + "FIRST_EXCEPTION", + "ALL_COMPLETED", + "wait", + "wait_for", + "as_completed", + "sleep", + "gather", + "shield", + "ensure_future", + "run_coroutine_threadsafe", + "current_task", + "all_tasks", + "_register_task", + "_unregister_task", + "_enter_task", + "_leave_task", +) _T = TypeVar("_T") _T1 = TypeVar("_T1") @@ -78,9 +62,6 @@ def ensure_future(coro_or_future: _FT, *, loop: AbstractEventLoop | None = ...) @overload def ensure_future(coro_or_future: Awaitable[_T], *, loop: AbstractEventLoop | None = ...) -> Task[_T]: ... -# Prior to Python 3.7 'async' was an alias for 'ensure_future'. -# It became a keyword in 3.7. - # `gather()` actually returns a list with length equal to the number # of tasks passed; however, Tuple is used similar to the annotation for # zip() because typing does not support variadic type variables. See @@ -334,24 +315,24 @@ class Task(Future[_T], Generic[_T]): def current_task(cls, loop: AbstractEventLoop | None = ...) -> Task[Any] | None: ... @classmethod def all_tasks(cls, loop: AbstractEventLoop | None = ...) -> set[Task[Any]]: ... - if sys.version_info < (3, 7): - def _wakeup(self, fut: Future[Any]) -> None: ... if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any) -> GenericAlias: ... -if sys.version_info >= (3, 7): - def all_tasks(loop: AbstractEventLoop | None = ...) -> set[Task[Any]]: ... - if sys.version_info >= (3, 11): - def create_task( - coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T], *, name: str | None = ..., context: Context | None = ... - ) -> Task[_T]: ... - elif sys.version_info >= (3, 8): - def create_task(coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T], *, name: str | None = ...) -> Task[_T]: ... - else: - def create_task(coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T]) -> Task[_T]: ... +def all_tasks(loop: AbstractEventLoop | None = ...) -> set[Task[Any]]: ... + +if sys.version_info >= (3, 11): + def create_task( + coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T], *, name: str | None = ..., context: Context | None = ... + ) -> Task[_T]: ... + +elif sys.version_info >= (3, 8): + def create_task(coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T], *, name: str | None = ...) -> Task[_T]: ... + +else: + def create_task(coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T]) -> Task[_T]: ... - def current_task(loop: AbstractEventLoop | None = ...) -> Task[Any] | None: ... - def _enter_task(loop: AbstractEventLoop, task: Task[Any]) -> None: ... - def _leave_task(loop: AbstractEventLoop, task: Task[Any]) -> None: ... - def _register_task(task: Task[Any]) -> None: ... - def _unregister_task(task: Task[Any]) -> None: ... +def current_task(loop: AbstractEventLoop | None = ...) -> Task[Any] | None: ... +def _enter_task(loop: AbstractEventLoop, task: Task[Any]) -> None: ... +def _leave_task(loop: AbstractEventLoop, task: Task[Any]) -> None: ... +def _register_task(task: Task[Any]) -> None: ... +def _unregister_task(task: Task[Any]) -> None: ... diff --git a/stdlib/asyncio/transports.pyi b/stdlib/asyncio/transports.pyi index 7e17beb9f630..be68cad5f894 100644 --- a/stdlib/asyncio/transports.pyi +++ b/stdlib/asyncio/transports.pyi @@ -1,14 +1,10 @@ -import sys from asyncio.events import AbstractEventLoop from asyncio.protocols import BaseProtocol from collections.abc import Mapping from socket import _Address from typing import Any -if sys.version_info >= (3, 7): - __all__ = ("BaseTransport", "ReadTransport", "WriteTransport", "Transport", "DatagramTransport", "SubprocessTransport") -else: - __all__ = ["BaseTransport", "ReadTransport", "WriteTransport", "Transport", "DatagramTransport", "SubprocessTransport"] +__all__ = ("BaseTransport", "ReadTransport", "WriteTransport", "Transport", "DatagramTransport", "SubprocessTransport") class BaseTransport: def __init__(self, extra: Mapping[Any, Any] | None = ...) -> None: ... @@ -19,9 +15,7 @@ class BaseTransport: def get_protocol(self) -> BaseProtocol: ... class ReadTransport(BaseTransport): - if sys.version_info >= (3, 7): - def is_reading(self) -> bool: ... - + def is_reading(self) -> bool: ... def pause_reading(self) -> None: ... def resume_reading(self) -> None: ... diff --git a/stdlib/asyncio/unix_events.pyi b/stdlib/asyncio/unix_events.pyi index ca28ee04125a..1d59af9f4377 100644 --- a/stdlib/asyncio/unix_events.pyi +++ b/stdlib/asyncio/unix_events.pyi @@ -3,12 +3,10 @@ import types from _typeshed import Self from abc import ABCMeta, abstractmethod from collections.abc import Callable -from socket import socket from typing import Any from typing_extensions import Literal -from .base_events import Server -from .events import AbstractEventLoop, BaseDefaultEventLoopPolicy, _ProtocolFactory, _SSLContext +from .events import AbstractEventLoop, BaseDefaultEventLoopPolicy from .selector_events import BaseSelectorEventLoop # This is also technically not available on Win, @@ -53,10 +51,8 @@ if sys.platform != "win32": "ThreadedChildWatcher", "DefaultEventLoopPolicy", ) - elif sys.version_info >= (3, 7): - __all__ = ("SelectorEventLoop", "AbstractChildWatcher", "SafeChildWatcher", "FastChildWatcher", "DefaultEventLoopPolicy") else: - __all__ = ["SelectorEventLoop", "AbstractChildWatcher", "SafeChildWatcher", "FastChildWatcher", "DefaultEventLoopPolicy"] + __all__ = ("SelectorEventLoop", "AbstractChildWatcher", "SafeChildWatcher", "FastChildWatcher", "DefaultEventLoopPolicy") # Doesn't actually have ABCMeta metaclass at runtime, but mypy complains if we don't have it in the stub. # See discussion in #7412 @@ -80,17 +76,7 @@ if sys.platform != "win32": def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ... def remove_child_handler(self, pid: int) -> bool: ... - class _UnixSelectorEventLoop(BaseSelectorEventLoop): - if sys.version_info < (3, 7): - async def create_unix_server( - self, - protocol_factory: _ProtocolFactory, - path: str | None = ..., - *, - sock: socket | None = ..., - backlog: int = ..., - ssl: _SSLContext = ..., - ) -> Server: ... + class _UnixSelectorEventLoop(BaseSelectorEventLoop): ... class _UnixDefaultEventLoopPolicy(BaseDefaultEventLoopPolicy): def get_child_watcher(self) -> AbstractChildWatcher: ... diff --git a/stdlib/asyncio/windows_events.pyi b/stdlib/asyncio/windows_events.pyi index d33210bc1297..ffb487fff03a 100644 --- a/stdlib/asyncio/windows_events.pyi +++ b/stdlib/asyncio/windows_events.pyi @@ -8,17 +8,14 @@ from typing_extensions import Literal from . import events, futures, proactor_events, selector_events, streams, windows_utils if sys.platform == "win32": - if sys.version_info >= (3, 7): - __all__ = ( - "SelectorEventLoop", - "ProactorEventLoop", - "IocpProactor", - "DefaultEventLoopPolicy", - "WindowsSelectorEventLoopPolicy", - "WindowsProactorEventLoopPolicy", - ) - else: - __all__ = ["SelectorEventLoop", "ProactorEventLoop", "IocpProactor", "DefaultEventLoopPolicy"] + __all__ = ( + "SelectorEventLoop", + "ProactorEventLoop", + "IocpProactor", + "DefaultEventLoopPolicy", + "WindowsSelectorEventLoopPolicy", + "WindowsProactorEventLoopPolicy", + ) NULL: Literal[0] INFINITE: Literal[0xFFFFFFFF] @@ -50,35 +47,24 @@ if sys.platform == "win32": def set_loop(self, loop: events.AbstractEventLoop) -> None: ... def select(self, timeout: int | None = ...) -> list[futures.Future[Any]]: ... def recv(self, conn: socket.socket, nbytes: int, flags: int = ...) -> futures.Future[bytes]: ... - if sys.version_info >= (3, 7): - def recv_into(self, conn: socket.socket, buf: WriteableBuffer, flags: int = ...) -> futures.Future[Any]: ... - + def recv_into(self, conn: socket.socket, buf: WriteableBuffer, flags: int = ...) -> futures.Future[Any]: ... def send(self, conn: socket.socket, buf: WriteableBuffer, flags: int = ...) -> futures.Future[Any]: ... def accept(self, listener: socket.socket) -> futures.Future[Any]: ... def connect(self, conn: socket.socket, address: bytes) -> futures.Future[Any]: ... - if sys.version_info >= (3, 7): - def sendfile(self, sock: socket.socket, file: IO[bytes], offset: int, count: int) -> futures.Future[Any]: ... - + def sendfile(self, sock: socket.socket, file: IO[bytes], offset: int, count: int) -> futures.Future[Any]: ... def accept_pipe(self, pipe: socket.socket) -> futures.Future[Any]: ... async def connect_pipe(self, address: bytes) -> windows_utils.PipeHandle: ... def wait_for_handle(self, handle: windows_utils.PipeHandle, timeout: int | None = ...) -> bool: ... def close(self) -> None: ... SelectorEventLoop = _WindowsSelectorEventLoop - if sys.version_info >= (3, 7): - class WindowsSelectorEventLoopPolicy(events.BaseDefaultEventLoopPolicy): - _loop_factory: ClassVar[type[SelectorEventLoop]] - def get_child_watcher(self) -> NoReturn: ... - def set_child_watcher(self, watcher: Any) -> NoReturn: ... + class WindowsSelectorEventLoopPolicy(events.BaseDefaultEventLoopPolicy): + _loop_factory: ClassVar[type[SelectorEventLoop]] + def get_child_watcher(self) -> NoReturn: ... + def set_child_watcher(self, watcher: Any) -> NoReturn: ... - class WindowsProactorEventLoopPolicy(events.BaseDefaultEventLoopPolicy): - _loop_factory: ClassVar[type[ProactorEventLoop]] - def get_child_watcher(self) -> NoReturn: ... - def set_child_watcher(self, watcher: Any) -> NoReturn: ... - DefaultEventLoopPolicy = WindowsSelectorEventLoopPolicy - else: - class _WindowsDefaultEventLoopPolicy(events.BaseDefaultEventLoopPolicy): - _loop_factory: ClassVar[type[SelectorEventLoop]] - def get_child_watcher(self) -> NoReturn: ... - def set_child_watcher(self, watcher: Any) -> NoReturn: ... - DefaultEventLoopPolicy = _WindowsDefaultEventLoopPolicy + class WindowsProactorEventLoopPolicy(events.BaseDefaultEventLoopPolicy): + _loop_factory: ClassVar[type[ProactorEventLoop]] + def get_child_watcher(self) -> NoReturn: ... + def set_child_watcher(self, watcher: Any) -> NoReturn: ... + DefaultEventLoopPolicy = WindowsSelectorEventLoopPolicy diff --git a/stdlib/asyncio/windows_utils.pyi b/stdlib/asyncio/windows_utils.pyi index db34356cd16d..bca154a5e702 100644 --- a/stdlib/asyncio/windows_utils.pyi +++ b/stdlib/asyncio/windows_utils.pyi @@ -7,13 +7,7 @@ from typing import Any, AnyStr, Protocol from typing_extensions import Literal if sys.platform == "win32": - if sys.version_info >= (3, 7): - __all__ = ("pipe", "Popen", "PIPE", "PipeHandle") - else: - __all__ = ["socketpair", "pipe", "Popen", "PIPE", "PipeHandle"] - import socket - - socketpair = socket.socketpair + __all__ = ("pipe", "Popen", "PIPE", "PipeHandle") class _WarnFunction(Protocol): def __call__( diff --git a/stdlib/binascii.pyi b/stdlib/binascii.pyi index 0656794d39d9..6f834f7868c3 100644 --- a/stdlib/binascii.pyi +++ b/stdlib/binascii.pyi @@ -7,12 +7,7 @@ from typing_extensions import TypeAlias _AsciiBuffer: TypeAlias = str | ReadableBuffer def a2b_uu(__data: _AsciiBuffer) -> bytes: ... - -if sys.version_info >= (3, 7): - def b2a_uu(__data: ReadableBuffer, *, backtick: bool = ...) -> bytes: ... - -else: - def b2a_uu(__data: ReadableBuffer) -> bytes: ... +def b2a_uu(__data: ReadableBuffer, *, backtick: bool = ...) -> bytes: ... if sys.version_info >= (3, 11): def a2b_base64(__data: _AsciiBuffer, *, strict_mode: bool = ...) -> bytes: ... diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 47edc31659f1..d63f7855c247 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -438,9 +438,7 @@ class str(Sequence[str]): def index(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... - if sys.version_info >= (3, 7): - def isascii(self) -> bool: ... - + def isascii(self) -> bool: ... def isdecimal(self) -> bool: ... def isdigit(self) -> bool: ... def isidentifier(self) -> bool: ... @@ -616,9 +614,7 @@ class bytes(ByteString): ) -> int: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... - if sys.version_info >= (3, 7): - def isascii(self) -> bool: ... - + def isascii(self) -> bool: ... def isdigit(self) -> bool: ... def islower(self) -> bool: ... def isspace(self) -> bool: ... @@ -728,9 +724,7 @@ class bytearray(MutableSequence[int], ByteString): def insert(self, __index: SupportsIndex, __item: SupportsIndex) -> None: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... - if sys.version_info >= (3, 7): - def isascii(self) -> bool: ... - + def isascii(self) -> bool: ... def isdigit(self) -> bool: ... def islower(self) -> bool: ... def isspace(self) -> bool: ... @@ -1195,10 +1189,7 @@ def all(__iterable: Iterable[object]) -> bool: ... def any(__iterable: Iterable[object]) -> bool: ... def ascii(__obj: object) -> str: ... def bin(__number: int | SupportsIndex) -> str: ... - -if sys.version_info >= (3, 7): - def breakpoint(*args: Any, **kws: Any) -> None: ... - +def breakpoint(*args: Any, **kws: Any) -> None: ... def callable(__obj: object) -> TypeGuard[Callable[..., object]]: ... def chr(__i: int) -> str: ... diff --git a/stdlib/calendar.pyi b/stdlib/calendar.pyi index 00b7054ba60a..4faee805333b 100644 --- a/stdlib/calendar.pyi +++ b/stdlib/calendar.pyi @@ -62,9 +62,8 @@ class Calendar: def yeardatescalendar(self, year: int, width: int = ...) -> list[list[int]]: ... def yeardays2calendar(self, year: int, width: int = ...) -> list[list[tuple[int, int]]]: ... def yeardayscalendar(self, year: int, width: int = ...) -> list[list[int]]: ... - if sys.version_info >= (3, 7): - def itermonthdays3(self, year: int, month: int) -> Iterable[tuple[int, int, int]]: ... - def itermonthdays4(self, year: int, month: int) -> Iterable[tuple[int, int, int, int]]: ... + def itermonthdays3(self, year: int, month: int) -> Iterable[tuple[int, int, int]]: ... + def itermonthdays4(self, year: int, month: int) -> Iterable[tuple[int, int, int, int]]: ... class TextCalendar(Calendar): def prweek(self, theweek: int, width: int) -> None: ... @@ -97,14 +96,13 @@ class HTMLCalendar(Calendar): def formatmonth(self, theyear: int, themonth: int, withyear: bool = ...) -> str: ... def formatyear(self, theyear: int, width: int = ...) -> str: ... def formatyearpage(self, theyear: int, width: int = ..., css: str | None = ..., encoding: str | None = ...) -> str: ... - if sys.version_info >= (3, 7): - cssclasses: list[str] - cssclass_noday: str - cssclasses_weekday_head: list[str] - cssclass_month_head: str - cssclass_month: str - cssclass_year: str - cssclass_year_head: str + cssclasses: list[str] + cssclass_noday: str + cssclasses_weekday_head: list[str] + cssclass_month_head: str + cssclass_month: str + cssclass_year: str + cssclass_year_head: str class different_locale: def __init__(self, locale: _LocaleType) -> None: ... diff --git a/stdlib/cgi.pyi b/stdlib/cgi.pyi index 59c0a27067f1..523b44793941 100644 --- a/stdlib/cgi.pyi +++ b/stdlib/cgi.pyi @@ -35,13 +35,9 @@ if sys.version_info < (3, 8): def parse_qs(qs: str, keep_blank_values: bool = ..., strict_parsing: bool = ...) -> dict[str, list[str]]: ... def parse_qsl(qs: str, keep_blank_values: bool = ..., strict_parsing: bool = ...) -> list[tuple[str, str]]: ... -if sys.version_info >= (3, 7): - def parse_multipart( - fp: IO[Any], pdict: SupportsGetItem[str, bytes], encoding: str = ..., errors: str = ..., separator: str = ... - ) -> dict[str, list[Any]]: ... - -else: - def parse_multipart(fp: IO[Any], pdict: SupportsGetItem[str, bytes]) -> dict[str, list[bytes]]: ... +def parse_multipart( + fp: IO[Any], pdict: SupportsGetItem[str, bytes], encoding: str = ..., errors: str = ..., separator: str = ... +) -> dict[str, list[Any]]: ... class _Environ(Protocol): def __getitem__(self, __k: str) -> str: ... diff --git a/stdlib/collections/__init__.pyi b/stdlib/collections/__init__.pyi index 5fff9f48c489..b546c45ab364 100644 --- a/stdlib/collections/__init__.pyi +++ b/stdlib/collections/__init__.pyi @@ -14,35 +14,6 @@ else: __all__ = ["ChainMap", "Counter", "OrderedDict", "UserDict", "UserList", "UserString", "defaultdict", "deque", "namedtuple"] -if sys.version_info < (3, 7): - __all__ += [ - "Awaitable", - "Coroutine", - "AsyncIterable", - "AsyncIterator", - "AsyncGenerator", - "Hashable", - "Iterable", - "Iterator", - "Generator", - "Reversible", - "Sized", - "Container", - "Callable", - "Collection", - "Set", - "MutableSet", - "Mapping", - "MutableMapping", - "MappingView", - "KeysView", - "ItemsView", - "ValuesView", - "Sequence", - "MutableSequence", - "ByteString", - ] - _S = TypeVar("_S") _T = TypeVar("_T") _T1 = TypeVar("_T1") @@ -53,20 +24,14 @@ _KT_co = TypeVar("_KT_co", covariant=True) _VT_co = TypeVar("_VT_co", covariant=True) # namedtuple is special-cased in the type checker; the initializer is ignored. -if sys.version_info >= (3, 7): - def namedtuple( - typename: str, - field_names: str | Iterable[str], - *, - rename: bool = ..., - module: str | None = ..., - defaults: Iterable[Any] | None = ..., - ) -> type[tuple[Any, ...]]: ... - -else: - def namedtuple( - typename: str, field_names: str | Iterable[str], *, verbose: bool = ..., rename: bool = ..., module: str | None = ... - ) -> type[tuple[Any, ...]]: ... +def namedtuple( + typename: str, + field_names: str | Iterable[str], + *, + rename: bool = ..., + module: str | None = ..., + defaults: Iterable[Any] | None = ..., +) -> type[tuple[Any, ...]]: ... class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): data: dict[_KT, _VT] @@ -88,8 +53,7 @@ class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __iter__(self) -> Iterator[_KT]: ... def __contains__(self, key: object) -> bool: ... def copy(self: Self) -> Self: ... - if sys.version_info >= (3, 7): - def __copy__(self: Self) -> Self: ... + def __copy__(self: Self) -> Self: ... # `UserDict.fromkeys` has the same semantics as `dict.fromkeys`, so should be kept in line with `dict.fromkeys`. # TODO: Much like `dict.fromkeys`, the true signature of `UserDict.fromkeys` is inexpressible in the current type system. @@ -142,9 +106,7 @@ class UserList(MutableSequence[_T]): def pop(self, i: int = ...) -> _T: ... def remove(self, item: _T) -> None: ... def copy(self: Self) -> Self: ... - if sys.version_info >= (3, 7): - def __copy__(self: Self) -> Self: ... - + def __copy__(self: Self) -> Self: ... def count(self, item: _T) -> int: ... # All arguments are passed to `list.index` at runtime, so the signature should be kept in line with `list.index`. def index(self, item: _T, __start: SupportsIndex = ..., __stop: SupportsIndex = ...) -> int: ... @@ -208,9 +170,7 @@ class UserString(Sequence[UserString]): def isspace(self) -> bool: ... def istitle(self) -> bool: ... def isupper(self) -> bool: ... - if sys.version_info >= (3, 7): - def isascii(self) -> bool: ... - + def isascii(self) -> bool: ... def join(self, seq: Iterable[str]) -> str: ... def ljust(self: Self, width: int, *args: Any) -> Self: ... def lower(self: Self) -> Self: ... diff --git a/stdlib/compileall.pyi b/stdlib/compileall.pyi index 7101fd05f717..dd1de3f496e7 100644 --- a/stdlib/compileall.pyi +++ b/stdlib/compileall.pyi @@ -1,10 +1,8 @@ import sys from _typeshed import StrPath +from py_compile import PycInvalidationMode from typing import Any, Protocol -if sys.version_info >= (3, 7): - from py_compile import PycInvalidationMode - __all__ = ["compile_dir", "compile_file", "compile_path"] class _SupportsSearch(Protocol): @@ -44,30 +42,6 @@ if sys.version_info >= (3, 9): hardlink_dupes: bool = ..., ) -> int: ... -elif sys.version_info >= (3, 7): - def compile_dir( - dir: StrPath, - maxlevels: int = ..., - ddir: StrPath | None = ..., - force: bool = ..., - rx: _SupportsSearch | None = ..., - quiet: int = ..., - legacy: bool = ..., - optimize: int = ..., - workers: int = ..., - invalidation_mode: PycInvalidationMode | None = ..., - ) -> int: ... - def compile_file( - fullname: StrPath, - ddir: StrPath | None = ..., - force: bool = ..., - rx: _SupportsSearch | None = ..., - quiet: int = ..., - legacy: bool = ..., - optimize: int = ..., - invalidation_mode: PycInvalidationMode | None = ..., - ) -> int: ... - else: def compile_dir( dir: StrPath, @@ -79,6 +53,7 @@ else: legacy: bool = ..., optimize: int = ..., workers: int = ..., + invalidation_mode: PycInvalidationMode | None = ..., ) -> int: ... def compile_file( fullname: StrPath, @@ -88,25 +63,15 @@ else: quiet: int = ..., legacy: bool = ..., optimize: int = ..., - ) -> int: ... - -if sys.version_info >= (3, 7): - def compile_path( - skip_curdir: bool = ..., - maxlevels: int = ..., - force: bool = ..., - quiet: int = ..., - legacy: bool = ..., - optimize: int = ..., invalidation_mode: PycInvalidationMode | None = ..., ) -> int: ... -else: - def compile_path( - skip_curdir: bool = ..., - maxlevels: int = ..., - force: bool = ..., - quiet: int = ..., - legacy: bool = ..., - optimize: int = ..., - ) -> int: ... +def compile_path( + skip_curdir: bool = ..., + maxlevels: int = ..., + force: bool = ..., + quiet: int = ..., + legacy: bool = ..., + optimize: int = ..., + invalidation_mode: PycInvalidationMode | None = ..., +) -> int: ... diff --git a/stdlib/concurrent/futures/__init__.pyi b/stdlib/concurrent/futures/__init__.pyi index dbf8ea3df857..3c9e53d62d6c 100644 --- a/stdlib/concurrent/futures/__init__.pyi +++ b/stdlib/concurrent/futures/__init__.pyi @@ -1,25 +1,10 @@ import sys -if sys.version_info >= (3, 7): - __all__ = ( - "FIRST_COMPLETED", - "FIRST_EXCEPTION", - "ALL_COMPLETED", - "CancelledError", - "TimeoutError", - "BrokenExecutor", - "Future", - "Executor", - "wait", - "as_completed", - "ProcessPoolExecutor", - "ThreadPoolExecutor", - ) - from ._base import ( ALL_COMPLETED as ALL_COMPLETED, FIRST_COMPLETED as FIRST_COMPLETED, FIRST_EXCEPTION as FIRST_EXCEPTION, + BrokenExecutor as BrokenExecutor, CancelledError as CancelledError, Executor as Executor, Future as Future, @@ -32,5 +17,18 @@ from .thread import ThreadPoolExecutor as ThreadPoolExecutor if sys.version_info >= (3, 8): from ._base import InvalidStateError as InvalidStateError -if sys.version_info >= (3, 7): - from ._base import BrokenExecutor as BrokenExecutor + +__all__ = ( + "FIRST_COMPLETED", + "FIRST_EXCEPTION", + "ALL_COMPLETED", + "CancelledError", + "TimeoutError", + "BrokenExecutor", + "Future", + "Executor", + "wait", + "as_completed", + "ProcessPoolExecutor", + "ThreadPoolExecutor", +) diff --git a/stdlib/concurrent/futures/_base.pyi b/stdlib/concurrent/futures/_base.pyi index 5b756d87d118..7a1e7e703fcd 100644 --- a/stdlib/concurrent/futures/_base.pyi +++ b/stdlib/concurrent/futures/_base.pyi @@ -30,8 +30,7 @@ class TimeoutError(Error): ... if sys.version_info >= (3, 8): class InvalidStateError(Error): ... -if sys.version_info >= (3, 7): - class BrokenExecutor(RuntimeError): ... +class BrokenExecutor(RuntimeError): ... _T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) diff --git a/stdlib/concurrent/futures/process.pyi b/stdlib/concurrent/futures/process.pyi index 0c3bea26c31f..e7900aa415cc 100644 --- a/stdlib/concurrent/futures/process.pyi +++ b/stdlib/concurrent/futures/process.pyi @@ -8,7 +8,7 @@ from types import TracebackType from typing import Any, Generic, TypeVar from weakref import ref -from ._base import Executor, Future +from ._base import BrokenExecutor, Executor, Future _threads_wakeups: MutableMapping[Any, Any] _global_shutdown: bool @@ -68,27 +68,26 @@ class _CallItem: kwargs: Mapping[str, Any] def __init__(self, work_id: int, fn: Callable[..., Any], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ... -if sys.version_info >= (3, 7): - class _SafeQueue(Queue[Future[Any]]): - pending_work_items: dict[int, _WorkItem[Any]] - shutdown_lock: Lock - thread_wakeup: _ThreadWakeup - if sys.version_info >= (3, 9): - def __init__( - self, - max_size: int | None = ..., - *, - ctx: BaseContext, - pending_work_items: dict[int, _WorkItem[Any]], - shutdown_lock: Lock, - thread_wakeup: _ThreadWakeup, - ) -> None: ... - else: - def __init__( - self, max_size: int | None = ..., *, ctx: BaseContext, pending_work_items: dict[int, _WorkItem[Any]] - ) -> None: ... - - def _on_queue_feeder_error(self, e: Exception, obj: _CallItem) -> None: ... +class _SafeQueue(Queue[Future[Any]]): + pending_work_items: dict[int, _WorkItem[Any]] + shutdown_lock: Lock + thread_wakeup: _ThreadWakeup + if sys.version_info >= (3, 9): + def __init__( + self, + max_size: int | None = ..., + *, + ctx: BaseContext, + pending_work_items: dict[int, _WorkItem[Any]], + shutdown_lock: Lock, + thread_wakeup: _ThreadWakeup, + ) -> None: ... + else: + def __init__( + self, max_size: int | None = ..., *, ctx: BaseContext, pending_work_items: dict[int, _WorkItem[Any]] + ) -> None: ... + + def _on_queue_feeder_error(self, e: Exception, obj: _CallItem) -> None: ... def _get_chunks(*iterables: Any, chunksize: int) -> Generator[tuple[Any, ...], None, None]: ... def _process_chunk(fn: Callable[..., Any], chunk: tuple[Any, None, None]) -> Generator[Any, None, None]: ... @@ -116,7 +115,7 @@ if sys.version_info >= (3, 11): max_tasks: int | None = ..., ) -> None: ... -elif sys.version_info >= (3, 7): +else: def _process_worker( call_queue: Queue[_CallItem], result_queue: SimpleQueue[_ResultItem], @@ -124,9 +123,6 @@ elif sys.version_info >= (3, 7): initargs: tuple[Any, ...], ) -> None: ... -else: - def _process_worker(call_queue: Queue[_CallItem], result_queue: SimpleQueue[_ResultItem]) -> None: ... - if sys.version_info >= (3, 9): class _ExecutorManagerThread(Thread): thread_wakeup: _ThreadWakeup @@ -155,13 +151,7 @@ _system_limited: bool | None def _check_system_limits() -> None: ... def _chain_from_iterable_of_lists(iterable: Iterable[MutableSequence[Any]]) -> Any: ... -if sys.version_info >= (3, 7): - from ._base import BrokenExecutor - - class BrokenProcessPool(BrokenExecutor): ... - -else: - class BrokenProcessPool(RuntimeError): ... +class BrokenProcessPool(BrokenExecutor): ... class ProcessPoolExecutor(Executor): _mp_context: BaseContext | None = ... @@ -189,7 +179,7 @@ class ProcessPoolExecutor(Executor): *, max_tasks_per_child: int | None = ..., ) -> None: ... - elif sys.version_info >= (3, 7): + else: def __init__( self, max_workers: int | None = ..., @@ -197,8 +187,6 @@ class ProcessPoolExecutor(Executor): initializer: Callable[..., object] | None = ..., initargs: tuple[Any, ...] = ..., ) -> None: ... - else: - def __init__(self, max_workers: int | None = ...) -> None: ... if sys.version_info >= (3, 9): def _start_executor_manager_thread(self) -> None: ... diff --git a/stdlib/concurrent/futures/thread.pyi b/stdlib/concurrent/futures/thread.pyi index 3579c17dbc6c..387ce0d7e438 100644 --- a/stdlib/concurrent/futures/thread.pyi +++ b/stdlib/concurrent/futures/thread.pyi @@ -5,7 +5,7 @@ from threading import Lock, Semaphore, Thread from typing import Any, Generic, TypeVar from weakref import ref -from ._base import Executor, Future +from ._base import BrokenExecutor, Executor, Future _threads_queues: Mapping[Any, Any] _shutdown: bool @@ -28,21 +28,14 @@ class _WorkItem(Generic[_S]): if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any) -> GenericAlias: ... -if sys.version_info >= (3, 7): - def _worker( - executor_reference: ref[Any], - work_queue: queue.SimpleQueue[Any], - initializer: Callable[..., object], - initargs: tuple[Any, ...], - ) -> None: ... - -else: - def _worker(executor_reference: ref[Any], work_queue: queue.Queue[Any]) -> None: ... - -if sys.version_info >= (3, 7): - from ._base import BrokenExecutor +def _worker( + executor_reference: ref[Any], + work_queue: queue.SimpleQueue[Any], + initializer: Callable[..., object], + initargs: tuple[Any, ...], +) -> None: ... - class BrokenThreadPool(BrokenExecutor): ... +class BrokenThreadPool(BrokenExecutor): ... class ThreadPoolExecutor(Executor): _max_workers: int @@ -54,21 +47,13 @@ class ThreadPoolExecutor(Executor): _thread_name_prefix: str | None = ... _initializer: Callable[..., None] | None = ... _initargs: tuple[Any, ...] = ... - if sys.version_info >= (3, 7): - _work_queue: queue.SimpleQueue[_WorkItem[Any]] - else: - _work_queue: queue.Queue[_WorkItem[Any]] - if sys.version_info >= (3, 7): - def __init__( - self, - max_workers: int | None = ..., - thread_name_prefix: str = ..., - initializer: Callable[..., object] | None = ..., - initargs: tuple[Any, ...] = ..., - ) -> None: ... - else: - def __init__(self, max_workers: int | None = ..., thread_name_prefix: str = ...) -> None: ... - + _work_queue: queue.SimpleQueue[_WorkItem[Any]] + def __init__( + self, + max_workers: int | None = ..., + thread_name_prefix: str = ..., + initializer: Callable[..., object] | None = ..., + initargs: tuple[Any, ...] = ..., + ) -> None: ... def _adjust_thread_count(self) -> None: ... - if sys.version_info >= (3, 7): - def _initializer_failed(self) -> None: ... + def _initializer_failed(self) -> None: ... diff --git a/stdlib/configparser.pyi b/stdlib/configparser.pyi index 96145f48cd4b..d3043466f572 100644 --- a/stdlib/configparser.pyi +++ b/stdlib/configparser.pyi @@ -1,5 +1,5 @@ import sys -from _typeshed import StrOrBytesPath, StrPath, SupportsWrite +from _typeshed import StrOrBytesPath, SupportsWrite from collections.abc import Callable, ItemsView, Iterable, Iterator, Mapping, MutableMapping, Sequence from typing import Any, ClassVar, Pattern, TypeVar, overload from typing_extensions import Literal, TypeAlias @@ -34,11 +34,6 @@ _ConverterCallback: TypeAlias = Callable[[str], Any] _ConvertersMap: TypeAlias = dict[str, _ConverterCallback] _T = TypeVar("_T") -if sys.version_info >= (3, 7): - _Path: TypeAlias = StrOrBytesPath -else: - _Path: TypeAlias = StrPath - DEFAULTSECT: Literal["DEFAULT"] MAX_INTERPOLATION_DEPTH: Literal[10] @@ -110,7 +105,7 @@ class RawConfigParser(_Parser): def has_section(self, section: str) -> bool: ... def options(self, section: str) -> list[str]: ... def has_option(self, section: str, option: str) -> bool: ... - def read(self, filenames: _Path | Iterable[_Path], encoding: str | None = ...) -> list[str]: ... + def read(self, filenames: StrOrBytesPath | Iterable[StrOrBytesPath], encoding: str | None = ...) -> list[str]: ... def read_file(self, f: Iterable[str], source: str | None = ...) -> None: ... def read_string(self, string: str, source: str = ...) -> None: ... def read_dict(self, dictionary: Mapping[str, Mapping[str, Any]], source: str = ...) -> None: ... diff --git a/stdlib/contextlib.pyi b/stdlib/contextlib.pyi index 81213b954093..dde87c041b26 100644 --- a/stdlib/contextlib.pyi +++ b/stdlib/contextlib.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import Self, StrOrBytesPath from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Generator, Iterator from types import TracebackType -from typing import IO, Any, ContextManager, Generic, Protocol, TypeVar, overload # noqa: Y027 +from typing import IO, Any, AsyncContextManager, ContextManager, Generic, Protocol, TypeVar, overload # noqa: Y022,Y027 from typing_extensions import ParamSpec, TypeAlias __all__ = [ @@ -14,23 +14,18 @@ __all__ = [ "redirect_stdout", "redirect_stderr", "suppress", + "AbstractAsyncContextManager", + "AsyncExitStack", + "asynccontextmanager", + "nullcontext", ] -if sys.version_info >= (3, 7): - __all__ += ["AbstractAsyncContextManager", "AsyncExitStack", "asynccontextmanager", "nullcontext"] - if sys.version_info >= (3, 10): __all__ += ["aclosing"] if sys.version_info >= (3, 11): __all__ += ["chdir"] -AbstractContextManager = ContextManager -if sys.version_info >= (3, 7): - from typing import AsyncContextManager # noqa: Y022 - - AbstractAsyncContextManager = AsyncContextManager - _T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) _T_io = TypeVar("_T_io", bound=IO[str] | None) @@ -40,12 +35,14 @@ _P = ParamSpec("_P") _ExitFunc: TypeAlias = Callable[[type[BaseException] | None, BaseException | None, TracebackType | None], bool | None] _CM_EF = TypeVar("_CM_EF", bound=AbstractContextManager[Any] | _ExitFunc) +AbstractContextManager = ContextManager +AbstractAsyncContextManager = AsyncContextManager + class ContextDecorator: def __call__(self, func: _F) -> _F: ... class _GeneratorContextManager(AbstractContextManager[_T_co], ContextDecorator, Generic[_T_co]): - # In Python <= 3.6, __init__ and all instance attributes are defined directly on this class. - # In Python >= 3.7, __init__ and all instance attributes are inherited from _GeneratorContextManagerBase + # __init__ and all instance attributes are actually inherited from _GeneratorContextManagerBase # _GeneratorContextManagerBase is more trouble than it's worth to include in the stub; see #6676 def __init__(self, func: Callable[..., Iterator[_T_co]], args: tuple[Any, ...], kwds: dict[str, Any]) -> None: ... gen: Generator[_T_co, Any, Any] @@ -76,7 +73,7 @@ if sys.version_info >= (3, 10): self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> bool | None: ... -elif sys.version_info >= (3, 7): +else: class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co], Generic[_T_co]): def __init__(self, func: Callable[..., AsyncIterator[_T_co]], args: tuple[Any, ...], kwds: dict[str, Any]) -> None: ... gen: AsyncGenerator[_T_co, Any] @@ -87,8 +84,7 @@ elif sys.version_info >= (3, 7): self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> bool | None: ... -if sys.version_info >= (3, 7): - def asynccontextmanager(func: Callable[_P, AsyncIterator[_T_co]]) -> Callable[_P, _AsyncGeneratorContextManager[_T_co]]: ... +def asynccontextmanager(func: Callable[_P, AsyncIterator[_T_co]]) -> Callable[_P, _AsyncGeneratorContextManager[_T_co]]: ... class _SupportsClose(Protocol): def close(self) -> object: ... @@ -135,26 +131,25 @@ class ExitStack: self, __exc_type: type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None ) -> bool: ... -if sys.version_info >= (3, 7): - _ExitCoroFunc: TypeAlias = Callable[[type[BaseException] | None, BaseException | None, TracebackType | None], Awaitable[bool]] - _ACM_EF = TypeVar("_ACM_EF", bound=AbstractAsyncContextManager[Any] | _ExitCoroFunc) - - class AsyncExitStack: - def __init__(self) -> None: ... - def enter_context(self, cm: AbstractContextManager[_T]) -> _T: ... - async def enter_async_context(self, cm: AbstractAsyncContextManager[_T]) -> _T: ... - def push(self, exit: _CM_EF) -> _CM_EF: ... - def push_async_exit(self, exit: _ACM_EF) -> _ACM_EF: ... - def callback(self, __callback: Callable[_P, _T], *args: _P.args, **kwds: _P.kwargs) -> Callable[_P, _T]: ... - def push_async_callback( - self, __callback: Callable[_P, Awaitable[_T]], *args: _P.args, **kwds: _P.kwargs - ) -> Callable[_P, Awaitable[_T]]: ... - def pop_all(self: Self) -> Self: ... - async def aclose(self) -> None: ... - async def __aenter__(self: Self) -> Self: ... - async def __aexit__( - self, __exc_type: type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None - ) -> bool: ... +_ExitCoroFunc: TypeAlias = Callable[[type[BaseException] | None, BaseException | None, TracebackType | None], Awaitable[bool]] +_ACM_EF = TypeVar("_ACM_EF", bound=AbstractAsyncContextManager[Any] | _ExitCoroFunc) + +class AsyncExitStack: + def __init__(self) -> None: ... + def enter_context(self, cm: AbstractContextManager[_T]) -> _T: ... + async def enter_async_context(self, cm: AbstractAsyncContextManager[_T]) -> _T: ... + def push(self, exit: _CM_EF) -> _CM_EF: ... + def push_async_exit(self, exit: _ACM_EF) -> _ACM_EF: ... + def callback(self, __callback: Callable[_P, _T], *args: _P.args, **kwds: _P.kwargs) -> Callable[_P, _T]: ... + def push_async_callback( + self, __callback: Callable[_P, Awaitable[_T]], *args: _P.args, **kwds: _P.kwargs + ) -> Callable[_P, Awaitable[_T]]: ... + def pop_all(self: Self) -> Self: ... + async def aclose(self) -> None: ... + async def __aenter__(self: Self) -> Self: ... + async def __aexit__( + self, __exc_type: type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None + ) -> bool: ... if sys.version_info >= (3, 10): class nullcontext(AbstractContextManager[_T], AbstractAsyncContextManager[_T]): @@ -168,7 +163,7 @@ if sys.version_info >= (3, 10): async def __aenter__(self) -> _T: ... async def __aexit__(self, *exctype: object) -> None: ... -elif sys.version_info >= (3, 7): +else: class nullcontext(AbstractContextManager[_T]): enter_result: _T @overload diff --git a/stdlib/crypt.pyi b/stdlib/crypt.pyi index 5083f1eebeed..83ad45d5c155 100644 --- a/stdlib/crypt.pyi +++ b/stdlib/crypt.pyi @@ -6,14 +6,7 @@ if sys.platform != "win32": METHOD_MD5: _Method METHOD_SHA256: _Method METHOD_SHA512: _Method - if sys.version_info >= (3, 7): - METHOD_BLOWFISH: _Method - + METHOD_BLOWFISH: _Method methods: list[_Method] - - if sys.version_info >= (3, 7): - def mksalt(method: _Method | None = ..., *, rounds: int | None = ...) -> str: ... - else: - def mksalt(method: _Method | None = ...) -> str: ... - + def mksalt(method: _Method | None = ..., *, rounds: int | None = ...) -> str: ... def crypt(word: str, salt: str | _Method | None = ...) -> str: ... diff --git a/stdlib/datetime.pyi b/stdlib/datetime.pyi index bcd3413ac38b..4f93eb7205da 100644 --- a/stdlib/datetime.pyi +++ b/stdlib/datetime.pyi @@ -51,9 +51,8 @@ class date: def today(cls: type[Self]) -> Self: ... @classmethod def fromordinal(cls: type[Self], __n: int) -> Self: ... - if sys.version_info >= (3, 7): - @classmethod - def fromisoformat(cls: type[Self], __date_string: str) -> Self: ... + @classmethod + def fromisoformat(cls: type[Self], __date_string: str) -> Self: ... if sys.version_info >= (3, 8): @classmethod def fromisocalendar(cls: type[Self], year: int, week: int, day: int) -> Self: ... @@ -135,10 +134,8 @@ class time: def __gt__(self, __other: time) -> bool: ... def __hash__(self) -> int: ... def isoformat(self, timespec: str = ...) -> str: ... - if sys.version_info >= (3, 7): - @classmethod - def fromisoformat(cls: type[Self], __time_string: str) -> Self: ... - + @classmethod + def fromisoformat(cls: type[Self], __time_string: str) -> Self: ... def strftime(self, __format: str) -> str: ... def __format__(self, __fmt: str) -> str: ... def utcoffset(self) -> timedelta | None: ... @@ -256,10 +253,8 @@ class datetime(date): def utcnow(cls: type[Self]) -> Self: ... @classmethod def combine(cls, date: _Date, time: _Time, tzinfo: _TzInfo | None = ...) -> datetime: ... - if sys.version_info >= (3, 7): - @classmethod - def fromisoformat(cls: type[Self], __date_string: str) -> Self: ... - + @classmethod + def fromisoformat(cls: type[Self], __date_string: str) -> Self: ... def timestamp(self) -> float: ... def utctimetuple(self) -> struct_time: ... def date(self) -> _Date: ... diff --git a/stdlib/dis.pyi b/stdlib/dis.pyi index 0b78e17b360b..dd31d981071f 100644 --- a/stdlib/dis.pyi +++ b/stdlib/dis.pyi @@ -114,11 +114,8 @@ if sys.version_info >= (3, 11): adaptive: bool = ..., ) -> None: ... -elif sys.version_info >= (3, 7): - def dis(x: _HaveCodeOrStringType | None = ..., *, file: IO[str] | None = ..., depth: int | None = ...) -> None: ... - else: - def dis(x: _HaveCodeOrStringType | None = ..., *, file: IO[str] | None = ...) -> None: ... + def dis(x: _HaveCodeOrStringType | None = ..., *, file: IO[str] | None = ..., depth: int | None = ...) -> None: ... if sys.version_info >= (3, 11): def disassemble( diff --git a/stdlib/email/_header_value_parser.pyi b/stdlib/email/_header_value_parser.pyi index abe6ec63abb1..7d1925c14a7c 100644 --- a/stdlib/email/_header_value_parser.pyi +++ b/stdlib/email/_header_value_parser.pyi @@ -20,8 +20,7 @@ EXTENDED_ATTRIBUTE_ENDS: Final[set[str]] def quote_string(value: Any) -> str: ... -if sys.version_info >= (3, 7): - rfc2047_matcher: Pattern[str] +rfc2047_matcher: Pattern[str] class TokenList(list[TokenList | Terminal]): token_type: str | None diff --git a/stdlib/enum.pyi b/stdlib/enum.pyi index 6063dc47b004..4d89f68a7b28 100644 --- a/stdlib/enum.pyi +++ b/stdlib/enum.pyi @@ -161,8 +161,7 @@ class Enum(metaclass=EnumMeta): def value(self) -> Any: ... _name_: str _value_: Any - if sys.version_info >= (3, 7): - _ignore_: str | list[str] + _ignore_: str | list[str] _order_: str __order__: str @classmethod diff --git a/stdlib/gc.pyi b/stdlib/gc.pyi index 98b92e109f82..d24b7c1f4c7c 100644 --- a/stdlib/gc.pyi +++ b/stdlib/gc.pyi @@ -26,11 +26,9 @@ if sys.version_info >= (3, 8): else: def get_objects() -> list[Any]: ... -if sys.version_info >= (3, 7): - def freeze() -> None: ... - def unfreeze() -> None: ... - def get_freeze_count() -> int: ... - +def freeze() -> None: ... +def unfreeze() -> None: ... +def get_freeze_count() -> int: ... def get_referents(*objs: Any) -> list[Any]: ... def get_referrers(*objs: Any) -> list[Any]: ... def get_stats() -> list[dict[str, Any]]: ... diff --git a/stdlib/hmac.pyi b/stdlib/hmac.pyi index a7bf15493f0b..af69fc7ea46d 100644 --- a/stdlib/hmac.pyi +++ b/stdlib/hmac.pyi @@ -40,6 +40,4 @@ class HMAC: def compare_digest(__a: ReadableBuffer, __b: ReadableBuffer) -> bool: ... @overload def compare_digest(__a: AnyStr, __b: AnyStr) -> bool: ... - -if sys.version_info >= (3, 7): - def digest(key: bytes, msg: ReadableBuffer, digest: _DigestMod) -> bytes: ... +def digest(key: bytes, msg: ReadableBuffer, digest: _DigestMod) -> bytes: ... diff --git a/stdlib/http/__init__.pyi b/stdlib/http/__init__.pyi index 10c1d5926e84..d4b44f2eb99b 100644 --- a/stdlib/http/__init__.pyi +++ b/stdlib/http/__init__.pyi @@ -72,8 +72,7 @@ class HTTPStatus(IntEnum): LOOP_DETECTED: int NOT_EXTENDED: int NETWORK_AUTHENTICATION_REQUIRED: int - if sys.version_info >= (3, 7): - MISDIRECTED_REQUEST: int + MISDIRECTED_REQUEST: int if sys.version_info >= (3, 8): UNAVAILABLE_FOR_LEGAL_REASONS: int if sys.version_info >= (3, 9): diff --git a/stdlib/http/client.pyi b/stdlib/http/client.pyi index 235b6d6b4951..949ac9289fa5 100644 --- a/stdlib/http/client.pyi +++ b/stdlib/http/client.pyi @@ -1,7 +1,6 @@ import email.message import io import ssl -import sys import types from _typeshed import Self, WriteableBuffer from collections.abc import Callable, Iterable, Iterator, Mapping @@ -141,19 +140,14 @@ class HTTPResponse(io.BufferedIOBase, BinaryIO): # This is an API stub only for the class below, not a class itself. # urllib.request uses it for a parameter. class _HTTPConnectionProtocol(Protocol): - if sys.version_info >= (3, 7): - def __call__( - self, - host: str, - port: int | None = ..., - timeout: float = ..., - source_address: tuple[str, int] | None = ..., - blocksize: int = ..., - ) -> HTTPConnection: ... - else: - def __call__( - self, host: str, port: int | None = ..., timeout: float = ..., source_address: tuple[str, int] | None = ... - ) -> HTTPConnection: ... + def __call__( + self, + host: str, + port: int | None = ..., + timeout: float = ..., + source_address: tuple[str, int] | None = ..., + blocksize: int = ..., + ) -> HTTPConnection: ... class HTTPConnection: auto_open: int # undocumented @@ -164,20 +158,14 @@ class HTTPConnection: host: str port: int sock: Any - if sys.version_info >= (3, 7): - def __init__( - self, - host: str, - port: int | None = ..., - timeout: float | None = ..., - source_address: tuple[str, int] | None = ..., - blocksize: int = ..., - ) -> None: ... - else: - def __init__( - self, host: str, port: int | None = ..., timeout: float | None = ..., source_address: tuple[str, int] | None = ... - ) -> None: ... - + def __init__( + self, + host: str, + port: int | None = ..., + timeout: float | None = ..., + source_address: tuple[str, int] | None = ..., + blocksize: int = ..., + ) -> None: ... def request( self, method: str, url: str, body: _DataType | None = ..., headers: Mapping[str, str] = ..., *, encode_chunked: bool = ... ) -> None: ... @@ -192,33 +180,19 @@ class HTTPConnection: def send(self, data: _DataType) -> None: ... class HTTPSConnection(HTTPConnection): - if sys.version_info >= (3, 7): - def __init__( - self, - host: str, - port: int | None = ..., - key_file: str | None = ..., - cert_file: str | None = ..., - timeout: float | None = ..., - source_address: tuple[str, int] | None = ..., - *, - context: ssl.SSLContext | None = ..., - check_hostname: bool | None = ..., - blocksize: int = ..., - ) -> None: ... - else: - def __init__( - self, - host: str, - port: int | None = ..., - key_file: str | None = ..., - cert_file: str | None = ..., - timeout: float | None = ..., - source_address: tuple[str, int] | None = ..., - *, - context: ssl.SSLContext | None = ..., - check_hostname: bool | None = ..., - ) -> None: ... + def __init__( + self, + host: str, + port: int | None = ..., + key_file: str | None = ..., + cert_file: str | None = ..., + timeout: float | None = ..., + source_address: tuple[str, int] | None = ..., + *, + context: ssl.SSLContext | None = ..., + check_hostname: bool | None = ..., + blocksize: int = ..., + ) -> None: ... class HTTPException(Exception): ... diff --git a/stdlib/http/cookies.pyi b/stdlib/http/cookies.pyi index e5aa2c1609db..e2fe44d305ef 100644 --- a/stdlib/http/cookies.pyi +++ b/stdlib/http/cookies.pyi @@ -30,11 +30,7 @@ class Morsel(dict[str, Any], Generic[_T]): @property def key(self) -> str: ... def __init__(self) -> None: ... - if sys.version_info >= (3, 7): - 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 set(self, key: str, val: str, coded_val: _T) -> None: ... 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[override] diff --git a/stdlib/http/server.pyi b/stdlib/http/server.pyi index ad314cec1541..e73497bb18bc 100644 --- a/stdlib/http/server.pyi +++ b/stdlib/http/server.pyi @@ -1,23 +1,18 @@ import email.message import io import socketserver -import sys from _typeshed import StrPath, SupportsRead, SupportsWrite from collections.abc import Mapping, Sequence from typing import Any, AnyStr, BinaryIO, ClassVar -if sys.version_info >= (3, 7): - __all__ = ["HTTPServer", "ThreadingHTTPServer", "BaseHTTPRequestHandler", "SimpleHTTPRequestHandler", "CGIHTTPRequestHandler"] -else: - __all__ = ["HTTPServer", "BaseHTTPRequestHandler", "SimpleHTTPRequestHandler", "CGIHTTPRequestHandler"] +__all__ = ["HTTPServer", "ThreadingHTTPServer", "BaseHTTPRequestHandler", "SimpleHTTPRequestHandler", "CGIHTTPRequestHandler"] class HTTPServer(socketserver.TCPServer): server_name: str server_port: int -if sys.version_info >= (3, 7): - class ThreadingHTTPServer(socketserver.ThreadingMixIn, HTTPServer): - daemon_threads: bool # undocumented +class ThreadingHTTPServer(socketserver.ThreadingMixIn, HTTPServer): + daemon_threads: bool # undocumented class BaseHTTPRequestHandler(socketserver.StreamRequestHandler): client_address: tuple[str, int] @@ -60,13 +55,9 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler): class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): server_version: str extensions_map: dict[str, str] - if sys.version_info >= (3, 7): - def __init__( - self, request: bytes, client_address: tuple[str, int], server: socketserver.BaseServer, directory: str | None = ... - ) -> None: ... - else: - def __init__(self, request: bytes, client_address: tuple[str, int], server: socketserver.BaseServer) -> None: ... - + def __init__( + self, request: bytes, client_address: tuple[str, int], server: socketserver.BaseServer, directory: str | None = ... + ) -> None: ... def do_GET(self) -> None: ... def do_HEAD(self) -> None: ... def send_head(self) -> io.BytesIO | BinaryIO | None: ... # undocumented diff --git a/stdlib/importlib/abc.pyi b/stdlib/importlib/abc.pyi index 805910329b64..42b56d88d75b 100644 --- a/stdlib/importlib/abc.pyi +++ b/stdlib/importlib/abc.pyi @@ -96,21 +96,20 @@ class FileLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta): def get_filename(self, name: str | None = ...) -> _Path: ... def load_module(self, name: str | None = ...) -> types.ModuleType: ... -if sys.version_info >= (3, 7): - class ResourceReader(metaclass=ABCMeta): +class ResourceReader(metaclass=ABCMeta): + @abstractmethod + def open_resource(self, resource: StrOrBytesPath) -> IO[bytes]: ... + @abstractmethod + def resource_path(self, resource: StrOrBytesPath) -> str: ... + if sys.version_info >= (3, 10): @abstractmethod - def open_resource(self, resource: StrOrBytesPath) -> IO[bytes]: ... + def is_resource(self, path: str) -> bool: ... + else: @abstractmethod - def resource_path(self, resource: StrOrBytesPath) -> str: ... - if sys.version_info >= (3, 10): - @abstractmethod - def is_resource(self, path: str) -> bool: ... - else: - @abstractmethod - def is_resource(self, name: str) -> bool: ... + def is_resource(self, name: str) -> bool: ... - @abstractmethod - def contents(self) -> Iterator[str]: ... + @abstractmethod + def contents(self) -> Iterator[str]: ... if sys.version_info >= (3, 9): @runtime_checkable diff --git a/stdlib/importlib/util.pyi b/stdlib/importlib/util.pyi index 2546c2c7882f..dca4778fd416 100644 --- a/stdlib/importlib/util.pyi +++ b/stdlib/importlib/util.pyi @@ -1,6 +1,5 @@ import importlib.abc import importlib.machinery -import sys import types from _typeshed import StrOrBytesPath from collections.abc import Callable @@ -39,5 +38,4 @@ class LazyLoader(importlib.abc.Loader): def create_module(self, spec: importlib.machinery.ModuleSpec) -> types.ModuleType | None: ... def exec_module(self, module: types.ModuleType) -> None: ... -if sys.version_info >= (3, 7): - def source_hash(source_bytes: bytes) -> int: ... +def source_hash(source_bytes: bytes) -> int: ... diff --git a/stdlib/inspect.pyi b/stdlib/inspect.pyi index 53c0c0f6f08e..74080af9389b 100644 --- a/stdlib/inspect.pyi +++ b/stdlib/inspect.pyi @@ -9,6 +9,7 @@ from types import ( AsyncGeneratorType, BuiltinFunctionType, BuiltinMethodType, + ClassMethodDescriptorType, CodeType, CoroutineType, FrameType, @@ -16,23 +17,16 @@ from types import ( GeneratorType, GetSetDescriptorType, LambdaType, + MemberDescriptorType, + MethodDescriptorType, MethodType, + MethodWrapperType, ModuleType, TracebackType, + WrapperDescriptorType, ) -from typing_extensions import TypeAlias - -if sys.version_info >= (3, 7): - from types import ( - ClassMethodDescriptorType, - WrapperDescriptorType, - MemberDescriptorType, - MethodDescriptorType, - MethodWrapperType, - ) - from typing import Any, ClassVar, NamedTuple, Protocol, TypeVar, Union -from typing_extensions import Literal, ParamSpec, TypeGuard +from typing_extensions import Literal, ParamSpec, TypeAlias, TypeGuard if sys.version_info >= (3, 11): __all__ = [ @@ -214,29 +208,20 @@ def isbuiltin(object: object) -> TypeGuard[BuiltinFunctionType]: ... if sys.version_info >= (3, 11): def ismethodwrapper(object: object) -> TypeGuard[MethodWrapperType]: ... -if sys.version_info >= (3, 7): - def isroutine( - object: object, - ) -> TypeGuard[ - FunctionType - | LambdaType - | MethodType - | BuiltinFunctionType - | BuiltinMethodType - | WrapperDescriptorType - | MethodDescriptorType - | ClassMethodDescriptorType - ]: ... - def ismethoddescriptor(object: object) -> TypeGuard[MethodDescriptorType]: ... - def ismemberdescriptor(object: object) -> TypeGuard[MemberDescriptorType]: ... - -else: - def isroutine( - object: object, - ) -> TypeGuard[FunctionType | LambdaType | MethodType | BuiltinFunctionType | BuiltinMethodType]: ... - def ismethoddescriptor(object: object) -> bool: ... - def ismemberdescriptor(object: object) -> bool: ... - +def isroutine( + object: object, +) -> TypeGuard[ + FunctionType + | LambdaType + | MethodType + | BuiltinFunctionType + | BuiltinMethodType + | WrapperDescriptorType + | MethodDescriptorType + | ClassMethodDescriptorType +]: ... +def ismethoddescriptor(object: object) -> TypeGuard[MethodDescriptorType]: ... +def ismemberdescriptor(object: object) -> TypeGuard[MemberDescriptorType]: ... def isabstract(object: object) -> bool: ... def isgetsetdescriptor(object: object) -> TypeGuard[GetSetDescriptorType]: ... def isdatadescriptor(object: object) -> TypeGuard[_SupportsSet[Any, Any] | _SupportsDelete[Any]]: ... diff --git a/stdlib/io.pyi b/stdlib/io.pyi index 0670b65fe359..c92fe1644053 100644 --- a/stdlib/io.pyi +++ b/stdlib/io.pyi @@ -110,19 +110,13 @@ class BytesIO(BufferedIOBase, BinaryIO): def __enter__(self: Self) -> Self: ... def getvalue(self) -> bytes: ... def getbuffer(self) -> memoryview: ... - if sys.version_info >= (3, 7): - def read1(self, __size: int | None = ...) -> bytes: ... - else: - def read1(self, __size: int | None) -> bytes: ... # type: ignore[override] + def read1(self, __size: int | None = ...) -> bytes: ... class BufferedReader(BufferedIOBase, BinaryIO): def __enter__(self: Self) -> Self: ... def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... def peek(self, __size: int = ...) -> bytes: ... - if sys.version_info >= (3, 7): - def read1(self, __size: int = ...) -> bytes: ... - else: - def read1(self, __size: int) -> bytes: ... # type: ignore[override] + def read1(self, __size: int = ...) -> bytes: ... class BufferedWriter(BufferedIOBase, BinaryIO): def __enter__(self: Self) -> Self: ... @@ -133,10 +127,7 @@ class BufferedRandom(BufferedReader, BufferedWriter): def __enter__(self: Self) -> Self: ... def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... def seek(self, __target: int, __whence: int = ...) -> int: ... - if sys.version_info >= (3, 7): - def read1(self, __size: int = ...) -> bytes: ... - else: - def read1(self, __size: int) -> bytes: ... # type: ignore[override] + def read1(self, __size: int = ...) -> bytes: ... class BufferedRWPair(BufferedIOBase): def __init__(self, reader: RawIOBase, writer: RawIOBase, buffer_size: int = ...) -> None: ... @@ -172,18 +163,17 @@ class TextIOWrapper(TextIOBase, TextIO): def closed(self) -> bool: ... @property def line_buffering(self) -> bool: ... - if sys.version_info >= (3, 7): - @property - def write_through(self) -> bool: ... - def reconfigure( - self, - *, - encoding: str | None = ..., - errors: str | None = ..., - newline: str | None = ..., - line_buffering: bool | None = ..., - write_through: bool | None = ..., - ) -> None: ... + @property + def write_through(self) -> bool: ... + def reconfigure( + self, + *, + encoding: str | None = ..., + errors: str | None = ..., + newline: str | None = ..., + line_buffering: bool | None = ..., + write_through: bool | None = ..., + ) -> None: ... # These are inherited from TextIOBase, but must exist in the stub to satisfy mypy. def __enter__(self: Self) -> Self: ... def __iter__(self) -> Iterator[str]: ... # type: ignore[override] diff --git a/stdlib/ipaddress.pyi b/stdlib/ipaddress.pyi index 1fdc6c57d8a8..4f9109363b53 100644 --- a/stdlib/ipaddress.pyi +++ b/stdlib/ipaddress.pyi @@ -109,10 +109,8 @@ class _BaseNetwork(_IPAddressBase, Container[_A], Iterable[_A], Generic[_A]): def overlaps(self, other: _BaseNetwork[IPv4Address] | _BaseNetwork[IPv6Address]) -> bool: ... @property def prefixlen(self) -> int: ... - if sys.version_info >= (3, 7): - def subnet_of(self: Self, other: Self) -> bool: ... - def supernet_of(self: Self, other: Self) -> bool: ... - + def subnet_of(self: Self, other: Self) -> bool: ... + def supernet_of(self: Self, other: Self) -> bool: ... def subnets(self: Self, prefixlen_diff: int = ..., new_prefix: int | None = ...) -> Iterator[Self]: ... def supernet(self: Self, prefixlen_diff: int = ..., new_prefix: int | None = ...) -> Self: ... @property diff --git a/stdlib/lib2to3/pgen2/token.pyi b/stdlib/lib2to3/pgen2/token.pyi index 2f944c40a02c..debcb2193987 100644 --- a/stdlib/lib2to3/pgen2/token.pyi +++ b/stdlib/lib2to3/pgen2/token.pyi @@ -1,5 +1,3 @@ -import sys - ENDMARKER: int NAME: int NUMBER: int @@ -59,8 +57,7 @@ ATEQUAL: int AWAIT: int ASYNC: int ERRORTOKEN: int -if sys.version_info >= (3, 7): - COLONEQUAL: int +COLONEQUAL: int N_TOKENS: int NT_OFFSET: int tok_name: dict[int, str] diff --git a/stdlib/lib2to3/pgen2/tokenize.pyi b/stdlib/lib2to3/pgen2/tokenize.pyi index e9da31ed1a0a..c9ad1e7bb411 100644 --- a/stdlib/lib2to3/pgen2/tokenize.pyi +++ b/stdlib/lib2to3/pgen2/tokenize.pyi @@ -1,4 +1,3 @@ -import sys from collections.abc import Callable, Iterable, Iterator from lib2to3.pgen2.token import * from typing_extensions import TypeAlias @@ -72,11 +71,9 @@ __all__ = [ "tokenize", "generate_tokens", "untokenize", + "COLONEQUAL", ] -if sys.version_info >= (3, 7): - __all__ += ["COLONEQUAL"] - _Coord: TypeAlias = tuple[int, int] _TokenEater: TypeAlias = Callable[[int, str, _Coord, _Coord, str], object] _TokenInfo: TypeAlias = tuple[int, str, _Coord, _Coord, str] diff --git a/stdlib/locale.pyi b/stdlib/locale.pyi index 393ddcbda841..9a3ea65d1b8b 100644 --- a/stdlib/locale.pyi +++ b/stdlib/locale.pyi @@ -122,13 +122,7 @@ def resetlocale(category: int = ...) -> None: ... def strcoll(__os1: _str, __os2: _str) -> int: ... def strxfrm(__string: _str) -> _str: ... def format(percent: _str, value: float | Decimal, grouping: bool = ..., monetary: bool = ..., *additional: Any) -> _str: ... - -if sys.version_info >= (3, 7): - def format_string(f: _str, val: Any, grouping: bool = ..., monetary: bool = ...) -> _str: ... - -else: - def format_string(f: _str, val: Any, grouping: bool = ...) -> _str: ... - +def format_string(f: _str, val: Any, grouping: bool = ..., monetary: bool = ...) -> _str: ... def currency(val: float | Decimal, symbol: bool = ..., grouping: bool = ..., international: bool = ...) -> _str: ... def delocalize(string: _str) -> _str: ... def atof(string: _str, func: Callable[[_str], float] = ...) -> float: ... diff --git a/stdlib/logging/__init__.pyi b/stdlib/logging/__init__.pyi index 6a8f66871a67..1e2f18da51d2 100644 --- a/stdlib/logging/__init__.pyi +++ b/stdlib/logging/__init__.pyi @@ -708,12 +708,7 @@ else: fatal = critical -if sys.version_info >= (3, 7): - def disable(level: int = ...) -> None: ... - -else: - def disable(level: int) -> None: ... - +def disable(level: int = ...) -> None: ... def addLevelName(level: int, levelName: str) -> None: ... def getLevelName(level: _Level) -> Any: ... @@ -781,8 +776,7 @@ class StreamHandler(Handler, Generic[_StreamT]): def __init__(self: StreamHandler[TextIO], stream: None = ...) -> None: ... @overload def __init__(self: StreamHandler[_StreamT], stream: _StreamT) -> None: ... - if sys.version_info >= (3, 7): - def setStream(self, stream: _StreamT) -> _StreamT | None: ... + def setStream(self, stream: _StreamT) -> _StreamT | None: ... if sys.version_info >= (3, 11): def __class_getitem__(cls, item: Any) -> GenericAlias: ... diff --git a/stdlib/logging/config.pyi b/stdlib/logging/config.pyi index 5993ba97df4b..f682f732b97b 100644 --- a/stdlib/logging/config.pyi +++ b/stdlib/logging/config.pyi @@ -1,10 +1,9 @@ import sys -from _typeshed import StrOrBytesPath, StrPath +from _typeshed import StrOrBytesPath from collections.abc import Callable, Sequence from configparser import RawConfigParser from threading import Thread from typing import IO, Any, Pattern -from typing_extensions import TypeAlias from . import _Level @@ -13,11 +12,6 @@ if sys.version_info >= (3, 8): else: from typing_extensions import Literal, TypedDict -if sys.version_info >= (3, 7): - _Path: TypeAlias = StrOrBytesPath -else: - _Path: TypeAlias = StrPath - DEFAULT_LOGGING_CONFIG_PORT: int RESET_ERROR: int # undocumented IDENTIFIER: Pattern[str] # undocumented @@ -53,7 +47,7 @@ def dictConfig(config: _DictConfigArgs | dict[str, Any]) -> None: ... if sys.version_info >= (3, 10): def fileConfig( - fname: _Path | IO[str] | RawConfigParser, + fname: StrOrBytesPath | IO[str] | RawConfigParser, defaults: dict[str, str] | None = ..., disable_existing_loggers: bool = ..., encoding: str | None = ..., @@ -61,7 +55,9 @@ if sys.version_info >= (3, 10): else: def fileConfig( - fname: _Path | IO[str] | RawConfigParser, defaults: dict[str, str] | None = ..., disable_existing_loggers: bool = ... + fname: StrOrBytesPath | IO[str] | RawConfigParser, + defaults: dict[str, str] | None = ..., + disable_existing_loggers: bool = ..., ) -> None: ... def valid_ident(s: str) -> Literal[True]: ... # undocumented diff --git a/stdlib/logging/handlers.pyi b/stdlib/logging/handlers.pyi index d3ea29075b81..db544a7fd9e8 100644 --- a/stdlib/logging/handlers.pyi +++ b/stdlib/logging/handlers.pyi @@ -5,14 +5,10 @@ import sys from _typeshed import StrPath from collections.abc import Callable from logging import FileHandler, Handler, LogRecord +from queue import Queue, SimpleQueue from socket import SocketKind, socket from typing import Any, ClassVar, Pattern -if sys.version_info >= (3, 7): - from queue import Queue, SimpleQueue -else: - from queue import Queue - DEFAULT_TCP_LOGGING_PORT: int DEFAULT_UDP_LOGGING_PORT: int DEFAULT_HTTP_LOGGING_PORT: int @@ -251,28 +247,16 @@ class HTTPHandler(Handler): def getConnection(self, host: str, secure: bool) -> http.client.HTTPConnection: ... # undocumented class QueueHandler(Handler): - if sys.version_info >= (3, 7): - queue: SimpleQueue[Any] | Queue[Any] # undocumented - def __init__(self, queue: SimpleQueue[Any] | Queue[Any]) -> None: ... - else: - queue: Queue[Any] # undocumented - def __init__(self, queue: Queue[Any]) -> None: ... - + queue: SimpleQueue[Any] | Queue[Any] # undocumented + def __init__(self, queue: SimpleQueue[Any] | Queue[Any]) -> None: ... def prepare(self, record: LogRecord) -> Any: ... def enqueue(self, record: LogRecord) -> None: ... class QueueListener: handlers: tuple[Handler, ...] # undocumented respect_handler_level: bool # undocumented - if sys.version_info >= (3, 7): - queue: SimpleQueue[Any] | Queue[Any] # undocumented - def __init__( - self, queue: SimpleQueue[Any] | Queue[Any], *handlers: Handler, respect_handler_level: bool = ... - ) -> None: ... - else: - queue: Queue[Any] # undocumented - def __init__(self, queue: Queue[Any], *handlers: Handler, respect_handler_level: bool = ...) -> None: ... - + queue: SimpleQueue[Any] | Queue[Any] # undocumented + def __init__(self, queue: SimpleQueue[Any] | Queue[Any], *handlers: Handler, respect_handler_level: bool = ...) -> None: ... def dequeue(self, block: bool) -> LogRecord: ... def prepare(self, record: LogRecord) -> Any: ... def start(self) -> None: ... diff --git a/stdlib/math.pyi b/stdlib/math.pyi index ada510d629ed..58eda98d8977 100644 --- a/stdlib/math.pyi +++ b/stdlib/math.pyi @@ -113,10 +113,7 @@ if sys.version_info >= (3, 8): def prod(__iterable: Iterable[_SupportsFloatOrIndex], *, start: _SupportsFloatOrIndex = ...) -> float: ... def radians(__x: _SupportsFloatOrIndex) -> float: ... - -if sys.version_info >= (3, 7): - def remainder(__x: _SupportsFloatOrIndex, __y: _SupportsFloatOrIndex) -> float: ... - +def remainder(__x: _SupportsFloatOrIndex, __y: _SupportsFloatOrIndex) -> float: ... def sin(__x: _SupportsFloatOrIndex) -> float: ... def sinh(__x: _SupportsFloatOrIndex) -> float: ... def sqrt(__x: _SupportsFloatOrIndex) -> float: ... diff --git a/stdlib/msilib/__init__.pyi b/stdlib/msilib/__init__.pyi index 968efbec7a6c..3b4b5ca8a78b 100644 --- a/stdlib/msilib/__init__.pyi +++ b/stdlib/msilib/__init__.pyi @@ -14,8 +14,6 @@ if sys.platform == "win32": ) AMD64: bool - if sys.version_info < (3, 7): - Itanium: bool Win64: bool datasizemask: Literal[0x00FF] diff --git a/stdlib/multiprocessing/managers.pyi b/stdlib/multiprocessing/managers.pyi index 5537ea937bae..dfbcb395ef1a 100644 --- a/stdlib/multiprocessing/managers.pyi +++ b/stdlib/multiprocessing/managers.pyi @@ -84,8 +84,6 @@ class DictProxy(BaseProxy, MutableMapping[_KT, _VT]): def keys(self) -> list[_KT]: ... # type: ignore[override] def values(self) -> list[tuple[_KT, _VT]]: ... # type: ignore[override] def items(self) -> list[_VT]: ... # type: ignore[override] - if sys.version_info < (3, 7): - def has_key(self, k: _KT) -> bool: ... class BaseListProxy(BaseProxy, MutableSequence[_T]): __builtins__: ClassVar[dict[str, Any]] diff --git a/stdlib/multiprocessing/process.pyi b/stdlib/multiprocessing/process.pyi index f903cef6fa72..7c8422e391c2 100644 --- a/stdlib/multiprocessing/process.pyi +++ b/stdlib/multiprocessing/process.pyi @@ -25,10 +25,8 @@ class BaseProcess: def run(self) -> None: ... def start(self) -> None: ... def terminate(self) -> None: ... - if sys.version_info >= (3, 7): - def kill(self) -> None: ... - def close(self) -> None: ... - + def kill(self) -> None: ... + def close(self) -> None: ... def join(self, timeout: float | None = ...) -> None: ... def is_alive(self) -> bool: ... @property diff --git a/stdlib/multiprocessing/synchronize.pyi b/stdlib/multiprocessing/synchronize.pyi index 7a86935f7d18..c89142f2cd3b 100644 --- a/stdlib/multiprocessing/synchronize.pyi +++ b/stdlib/multiprocessing/synchronize.pyi @@ -1,4 +1,3 @@ -import sys import threading from collections.abc import Callable from contextlib import AbstractContextManager @@ -20,11 +19,7 @@ class BoundedSemaphore(Semaphore): class Condition(AbstractContextManager[bool]): def __init__(self, lock: _LockLike | None = ..., *, ctx: BaseContext) -> None: ... - if sys.version_info >= (3, 7): - def notify(self, n: int = ...) -> None: ... - else: - def notify(self) -> None: ... - + def notify(self, n: int = ...) -> None: ... def notify_all(self) -> None: ... def wait(self, timeout: float | None = ...) -> bool: ... def wait_for(self, predicate: Callable[[], bool], timeout: float | None = ...) -> bool: ... diff --git a/stdlib/ntpath.pyi b/stdlib/ntpath.pyi index 78aa2346835c..0cd3e446475b 100644 --- a/stdlib/ntpath.pyi +++ b/stdlib/ntpath.pyi @@ -86,11 +86,6 @@ __all__ = [ "commonpath", ] -if sys.version_info < (3, 7): - __all__ += ["splitunc"] - - def splitunc(p: AnyStr) -> tuple[AnyStr, AnyStr]: ... # deprecated - altsep: LiteralString # First parameter is not actually pos-only, diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index 68c7634272e3..7500ba0e7f43 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -388,13 +388,8 @@ class DirEntry(Generic[AnyStr]): if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any) -> GenericAlias: ... -if sys.version_info >= (3, 7): - _StatVfsTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int, int, int] -else: - _StatVfsTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int, int] - @final -class statvfs_result(structseq[int], _StatVfsTuple): +class statvfs_result(structseq[int], tuple[int, int, int, int, int, int, int, int, int, int, int]): if sys.version_info >= (3, 10): __match_args__: Final = ( "f_bsize", @@ -428,9 +423,8 @@ class statvfs_result(structseq[int], _StatVfsTuple): def f_flag(self) -> int: ... @property def f_namemax(self) -> int: ... - if sys.version_info >= (3, 7): - @property - def f_fsid(self) -> int: ... + @property + def f_fsid(self) -> int: ... # ----- os function stubs ----- def fsencode(filename: StrOrBytesPath) -> bytes: ... @@ -595,13 +589,7 @@ def close(fd: int) -> None: ... def closerange(__fd_low: int, __fd_high: int) -> None: ... def device_encoding(fd: int) -> str | None: ... def dup(__fd: int) -> int: ... - -if sys.version_info >= (3, 7): - def dup2(fd: int, fd2: int, inheritable: bool = ...) -> int: ... - -else: - def dup2(fd: int, fd2: int, inheritable: bool = ...) -> None: ... - +def dup2(fd: int, fd2: int, inheritable: bool = ...) -> int: ... def fstat(fd: int) -> stat_result: ... def ftruncate(__fd: int, __length: int) -> None: ... def fsync(fd: FileDescriptorLike) -> None: ... @@ -636,13 +624,12 @@ if sys.platform != "win32": if sys.platform != "darwin": if sys.version_info >= (3, 10): RWF_APPEND: int # docs say available on 3.7+, stubtest says otherwise - if sys.version_info >= (3, 7): - def preadv(__fd: int, __buffers: Iterable[bytes], __offset: int, __flags: int = ...) -> int: ... - def pwritev(__fd: int, __buffers: Iterable[bytes], __offset: int, __flags: int = ...) -> int: ... - RWF_DSYNC: int - RWF_SYNC: int - RWF_HIPRI: int - RWF_NOWAIT: int + def preadv(__fd: int, __buffers: Iterable[bytes], __offset: int, __flags: int = ...) -> int: ... + def pwritev(__fd: int, __buffers: Iterable[bytes], __offset: int, __flags: int = ...) -> int: ... + RWF_DSYNC: int + RWF_SYNC: int + RWF_HIPRI: int + RWF_NOWAIT: int @overload def sendfile(out_fd: int, in_fd: int, offset: int | None, count: int) -> int: ... @overload @@ -742,21 +729,12 @@ class _ScandirIterator(Iterator[DirEntry[AnyStr]], AbstractContextManager[_Scand @overload def scandir(path: None = ...) -> _ScandirIterator[str]: ... - -if sys.version_info >= (3, 7): - @overload - def scandir(path: int) -> _ScandirIterator[str]: ... - +@overload +def scandir(path: int) -> _ScandirIterator[str]: ... @overload def scandir(path: GenericPath[AnyStr]) -> _ScandirIterator[AnyStr]: ... def stat(path: _FdOrAnyPath, *, dir_fd: int | None = ..., follow_symlinks: bool = ...) -> stat_result: ... -if sys.version_info < (3, 7): - @overload - def stat_float_times() -> bool: ... - @overload - def stat_float_times(__newvalue: bool) -> None: ... - if sys.platform != "win32": def statvfs(path: _FdOrAnyPath) -> statvfs_result: ... # Unix only @@ -783,34 +761,19 @@ def walk( ) -> Iterator[tuple[AnyStr, list[AnyStr], list[AnyStr]]]: ... if sys.platform != "win32": - if sys.version_info >= (3, 7): - @overload - def fwalk( - top: StrPath = ..., - topdown: bool = ..., - onerror: _OnError | None = ..., - *, - follow_symlinks: bool = ..., - dir_fd: int | None = ..., - ) -> Iterator[tuple[str, list[str], list[str], int]]: ... - @overload - def fwalk( - top: bytes, - topdown: bool = ..., - onerror: _OnError | None = ..., - *, - follow_symlinks: bool = ..., - dir_fd: int | None = ..., - ) -> Iterator[tuple[bytes, list[bytes], list[bytes], int]]: ... - else: - def fwalk( - top: StrPath = ..., - topdown: bool = ..., - onerror: _OnError | None = ..., - *, - follow_symlinks: bool = ..., - dir_fd: int | None = ..., - ) -> Iterator[tuple[str, list[str], list[str], int]]: ... + @overload + def fwalk( + top: StrPath = ..., + topdown: bool = ..., + onerror: _OnError | None = ..., + *, + follow_symlinks: bool = ..., + dir_fd: int | None = ..., + ) -> Iterator[tuple[str, list[str], list[str], int]]: ... + @overload + def fwalk( + top: bytes, topdown: bool = ..., onerror: _OnError | None = ..., *, follow_symlinks: bool = ..., dir_fd: int | None = ... + ) -> Iterator[tuple[bytes, list[bytes], list[bytes], int]]: ... if sys.platform == "linux": def getxattr(path: _FdOrAnyPath, attribute: StrOrBytesPath, *, follow_symlinks: bool = ...) -> bytes: ... def listxattr(path: _FdOrAnyPath | None = ..., *, follow_symlinks: bool = ...) -> list[str]: ... @@ -999,7 +962,7 @@ if sys.platform == "linux": def urandom(__size: int) -> bytes: ... -if sys.version_info >= (3, 7) and sys.platform != "win32": +if sys.platform != "win32": def register_at_fork( *, before: Callable[..., Any] | None = ..., diff --git a/stdlib/pathlib.pyi b/stdlib/pathlib.pyi index 65aead6cb4de..05ad3c55086b 100644 --- a/stdlib/pathlib.pyi +++ b/stdlib/pathlib.pyi @@ -159,8 +159,7 @@ class Path(PurePath): # so it's safer to pretend they don't exist def owner(self) -> str: ... def group(self) -> str: ... - if sys.version_info >= (3, 7): - def is_mount(self) -> bool: ... + def is_mount(self) -> bool: ... if sys.version_info >= (3, 9): def readlink(self: Self) -> Self: ... diff --git a/stdlib/pdb.pyi b/stdlib/pdb.pyi index 3c2cabe8abe2..6e95dcff6ee2 100644 --- a/stdlib/pdb.pyi +++ b/stdlib/pdb.pyi @@ -22,13 +22,7 @@ def run(statement: str, globals: dict[str, Any] | None = ..., locals: Mapping[st def runeval(expression: str, globals: dict[str, Any] | None = ..., locals: Mapping[str, Any] | None = ...) -> Any: ... def runctx(statement: str, globals: dict[str, Any], locals: Mapping[str, Any]) -> None: ... def runcall(func: Callable[_P, _T], *args: _P.args, **kwds: _P.kwargs) -> _T | None: ... - -if sys.version_info >= (3, 7): - def set_trace(*, header: str | None = ...) -> None: ... - -else: - def set_trace() -> None: ... - +def set_trace(*, header: str | None = ...) -> None: ... def post_mortem(t: TracebackType | None = ...) -> None: ... def pm() -> None: ... @@ -167,7 +161,7 @@ class Pdb(Bdb, Cmd): complete_whatis = _complete_expression complete_display = _complete_expression - if sys.version_info >= (3, 7) and sys.version_info < (3, 11): + if sys.version_info < (3, 11): def _runmodule(self, module_name: str) -> None: ... # undocumented diff --git a/stdlib/plistlib.pyi b/stdlib/plistlib.pyi index de5fe1b75ca0..89acc5b53851 100644 --- a/stdlib/plistlib.pyi +++ b/stdlib/plistlib.pyi @@ -23,30 +23,13 @@ elif sys.version_info >= (3, 8): "dumps", "UID", ] -elif sys.version_info >= (3, 7): - __all__ = [ - "readPlist", - "writePlist", - "readPlistFromBytes", - "writePlistToBytes", - "Data", - "InvalidFileException", - "FMT_XML", - "FMT_BINARY", - "load", - "dump", - "loads", - "dumps", - ] else: __all__ = [ "readPlist", "writePlist", "readPlistFromBytes", "writePlistToBytes", - "Plist", "Data", - "Dict", "InvalidFileException", "FMT_XML", "FMT_BINARY", @@ -105,21 +88,6 @@ if sys.version_info < (3, 9): def readPlistFromBytes(data: bytes) -> Any: ... def writePlistToBytes(value: Mapping[str, Any]) -> bytes: ... -if sys.version_info < (3, 7): - class _InternalDict(dict[str, Any]): - def __getattr__(self, attr: str) -> Any: ... - def __setattr__(self, attr: str, value: Any) -> None: ... - def __delattr__(self, attr: str) -> None: ... - - class Dict(_InternalDict): # deprecated - def __init__(self, **kwargs: Any) -> None: ... - - class Plist(_InternalDict): # deprecated - def __init__(self, **kwargs: Any) -> None: ... - @classmethod - def fromFile(cls: type[Self], pathOrFile: str | IO[bytes]) -> Self: ... - def write(self, pathOrFile: str | IO[bytes]) -> None: ... - if sys.version_info < (3, 9): class Data: data: bytes diff --git a/stdlib/posix.pyi b/stdlib/posix.pyi index e248db397ab8..7055f15f3d67 100644 --- a/stdlib/posix.pyi +++ b/stdlib/posix.pyi @@ -309,18 +309,17 @@ if sys.platform != "win32": copy_file_range as copy_file_range, memfd_create as memfd_create, ) - if sys.version_info >= (3, 7): - from os import register_at_fork as register_at_fork + from os import register_at_fork as register_at_fork - if sys.platform != "darwin": - from os import ( - RWF_DSYNC as RWF_DSYNC, - RWF_HIPRI as RWF_HIPRI, - RWF_NOWAIT as RWF_NOWAIT, - RWF_SYNC as RWF_SYNC, - preadv as preadv, - pwritev as pwritev, - ) + if sys.platform != "darwin": + from os import ( + RWF_DSYNC as RWF_DSYNC, + RWF_HIPRI as RWF_HIPRI, + RWF_NOWAIT as RWF_NOWAIT, + RWF_SYNC as RWF_SYNC, + preadv as preadv, + pwritev as pwritev, + ) # Not same as os.environ or os.environb # Because of this variable, we can't do "from posix import *" in os/__init__.pyi diff --git a/stdlib/pstats.pyi b/stdlib/pstats.pyi index 7868512e5ab9..7629cd63438f 100644 --- a/stdlib/pstats.pyi +++ b/stdlib/pstats.pyi @@ -2,32 +2,28 @@ import sys from _typeshed import Self, StrOrBytesPath from collections.abc import Iterable from cProfile import Profile as _cProfile +from enum import Enum from profile import Profile from typing import IO, Any, overload from typing_extensions import Literal, TypeAlias if sys.version_info >= (3, 9): __all__ = ["Stats", "SortKey", "FunctionProfile", "StatsProfile"] -elif sys.version_info >= (3, 7): - __all__ = ["Stats", "SortKey"] else: - __all__ = ["Stats"] + __all__ = ["Stats", "SortKey"] _Selector: TypeAlias = str | float | int -if sys.version_info >= (3, 7): - from enum import Enum - - class SortKey(str, Enum): - CALLS: str - CUMULATIVE: str - FILENAME: str - LINE: str - NAME: str - NFL: str - PCALLS: str - STDNAME: str - TIME: str +class SortKey(str, Enum): + CALLS: str + CUMULATIVE: str + FILENAME: str + LINE: str + NAME: str + NFL: str + PCALLS: str + STDNAME: str + TIME: str if sys.version_info >= (3, 9): from dataclasses import dataclass diff --git a/stdlib/py_compile.pyi b/stdlib/py_compile.pyi index c544a7941981..1e9b6c2cb209 100644 --- a/stdlib/py_compile.pyi +++ b/stdlib/py_compile.pyi @@ -1,10 +1,8 @@ +import enum import sys from typing import AnyStr -if sys.version_info >= (3, 7): - __all__ = ["compile", "main", "PyCompileError", "PycInvalidationMode"] -else: - __all__ = ["compile", "main", "PyCompileError"] +__all__ = ["compile", "main", "PyCompileError", "PycInvalidationMode"] class PyCompileError(Exception): exc_type_name: str @@ -13,14 +11,12 @@ class PyCompileError(Exception): msg: str def __init__(self, exc_type: type[BaseException], exc_value: BaseException, file: str, msg: str = ...) -> None: ... -if sys.version_info >= (3, 7): - import enum +class PycInvalidationMode(enum.Enum): + TIMESTAMP: int + CHECKED_HASH: int + UNCHECKED_HASH: int - class PycInvalidationMode(enum.Enum): - TIMESTAMP: int - CHECKED_HASH: int - UNCHECKED_HASH: int - def _get_default_invalidation_mode() -> PycInvalidationMode: ... +def _get_default_invalidation_mode() -> PycInvalidationMode: ... if sys.version_info >= (3, 8): def compile( @@ -33,7 +29,7 @@ if sys.version_info >= (3, 8): quiet: int = ..., ) -> AnyStr | None: ... -elif sys.version_info >= (3, 7): +else: def compile( file: AnyStr, cfile: AnyStr | None = ..., @@ -43,11 +39,6 @@ elif sys.version_info >= (3, 7): invalidation_mode: PycInvalidationMode | None = ..., ) -> AnyStr | None: ... -else: - def compile( - file: AnyStr, cfile: AnyStr | None = ..., dfile: AnyStr | None = ..., doraise: bool = ..., optimize: int = ... - ) -> AnyStr | None: ... - if sys.version_info >= (3, 10): def main() -> None: ... diff --git a/stdlib/pyclbr.pyi b/stdlib/pyclbr.pyi index 3033833a8162..bbff5a11e9e3 100644 --- a/stdlib/pyclbr.pyi +++ b/stdlib/pyclbr.pyi @@ -14,9 +14,8 @@ class Class: if sys.version_info >= (3, 10): end_lineno: int | None - if sys.version_info >= (3, 7): - parent: Class | None - children: dict[str, Class | Function] + parent: Class | None + children: dict[str, Class | Function] if sys.version_info >= (3, 10): def __init__( @@ -30,12 +29,10 @@ class Class: *, end_lineno: int | None = ..., ) -> None: ... - elif sys.version_info >= (3, 7): + else: def __init__( self, module: str, name: str, super: list[Class | str] | None, file: str, lineno: int, parent: Class | None = ... ) -> None: ... - else: - def __init__(self, module: str, name: str, super: list[Class | str] | None, file: str, lineno: int) -> None: ... class Function: module: str @@ -47,9 +44,8 @@ class Function: end_lineno: int | None is_async: bool - if sys.version_info >= (3, 7): - parent: Function | Class | None - children: dict[str, Class | Function] + parent: Function | Class | None + children: dict[str, Class | Function] if sys.version_info >= (3, 10): def __init__( diff --git a/stdlib/queue.pyi b/stdlib/queue.pyi index 532d5d98344d..7ea4beb664c5 100644 --- a/stdlib/queue.pyi +++ b/stdlib/queue.pyi @@ -5,10 +5,7 @@ from typing import Any, Generic, TypeVar if sys.version_info >= (3, 9): from types import GenericAlias -if sys.version_info >= (3, 7): - __all__ = ["Empty", "Full", "Queue", "PriorityQueue", "LifoQueue", "SimpleQueue"] -else: - __all__ = ["Empty", "Full", "Queue", "PriorityQueue", "LifoQueue"] +__all__ = ["Empty", "Full", "Queue", "PriorityQueue", "LifoQueue", "SimpleQueue"] _T = TypeVar("_T") @@ -49,14 +46,13 @@ class PriorityQueue(Queue[_T]): class LifoQueue(Queue[_T]): queue: list[_T] -if sys.version_info >= (3, 7): - class SimpleQueue(Generic[_T]): - def __init__(self) -> None: ... - def empty(self) -> bool: ... - def get(self, block: bool = ..., timeout: float | None = ...) -> _T: ... - def get_nowait(self) -> _T: ... - def put(self, item: _T, block: bool = ..., timeout: float | None = ...) -> None: ... - def put_nowait(self, item: _T) -> None: ... - def qsize(self) -> int: ... - if sys.version_info >= (3, 9): - def __class_getitem__(cls, item: Any) -> GenericAlias: ... +class SimpleQueue(Generic[_T]): + def __init__(self) -> None: ... + def empty(self) -> bool: ... + def get(self, block: bool = ..., timeout: float | None = ...) -> _T: ... + def get_nowait(self) -> _T: ... + def put(self, item: _T, block: bool = ..., timeout: float | None = ...) -> None: ... + def put_nowait(self, item: _T) -> None: ... + def qsize(self) -> int: ... + if sys.version_info >= (3, 9): + def __class_getitem__(cls, item: Any) -> GenericAlias: ... diff --git a/stdlib/re.pyi b/stdlib/re.pyi index bdabf32d895e..17b2ec011168 100644 --- a/stdlib/re.pyi +++ b/stdlib/re.pyi @@ -4,15 +4,9 @@ import sys from _typeshed import ReadableBuffer from collections.abc import Callable, Iterator from sre_constants import error as error -from typing import Any, AnyStr, overload +from typing import Any, AnyStr, Match as Match, Pattern as Pattern, overload from typing_extensions import TypeAlias -# ----- re variables and constants ----- -if sys.version_info >= (3, 7): - from typing import Match as Match, Pattern as Pattern -else: - from typing import Match, Pattern - __all__ = [ "match", "fullmatch", @@ -41,14 +35,15 @@ __all__ = [ "DOTALL", "VERBOSE", "UNICODE", + "Match", + "Pattern", ] -if sys.version_info >= (3, 7): - __all__ += ["Match", "Pattern"] - if sys.version_info >= (3, 11): __all__ += ["NOFLAG", "RegexFlag"] +# ----- re variables and constants ----- + class RegexFlag(enum.IntFlag): A = sre_compile.SRE_FLAG_ASCII ASCII = A @@ -91,10 +86,6 @@ if sys.version_info >= (3, 11): NOFLAG = RegexFlag.NOFLAG _FlagsType: TypeAlias = int | RegexFlag -if sys.version_info < (3, 7): - # undocumented - _pattern_type: type - # Type-wise the compile() overloads are unnecessary, they could also be modeled using # unions in the parameter types. However mypy has a bug regarding TypeVar # constraints (https://github.com/python/mypy/issues/11880), diff --git a/stdlib/shlex.pyi b/stdlib/shlex.pyi index fe0f80ba26c1..f9d660594a5a 100644 --- a/stdlib/shlex.pyi +++ b/stdlib/shlex.pyi @@ -30,11 +30,8 @@ class shlex(Iterable[str]): lineno: int token: str eof: str - if sys.version_info >= (3, 7): - @property - def punctuation_chars(self) -> str: ... - else: - punctuation_chars: str + @property + def punctuation_chars(self) -> str: ... def __init__( self, instream: str | TextIO | None = ..., diff --git a/stdlib/shutil.pyi b/stdlib/shutil.pyi index b6d0b9dbf7f3..7b60bf04e1a3 100644 --- a/stdlib/shutil.pyi +++ b/stdlib/shutil.pyi @@ -155,14 +155,7 @@ def register_archive_format( name: str, function: Callable[[str, str], object], extra_args: None = ..., description: str = ... ) -> None: ... def unregister_archive_format(name: str) -> None: ... - -if sys.version_info >= (3, 7): - def unpack_archive(filename: StrPath, extract_dir: StrPath | None = ..., format: str | None = ...) -> None: ... - -else: - # See http://bugs.python.org/issue30218 - def unpack_archive(filename: str, extract_dir: StrPath | None = ..., format: str | None = ...) -> None: ... - +def unpack_archive(filename: StrPath, extract_dir: StrPath | None = ..., format: str | None = ...) -> None: ... @overload def register_unpack_format( name: str, diff --git a/stdlib/signal.pyi b/stdlib/signal.pyi index a9d6ca28f8d7..8e9bd990a2c2 100644 --- a/stdlib/signal.pyi +++ b/stdlib/signal.pyi @@ -174,11 +174,7 @@ if sys.version_info >= (3, 8): def valid_signals() -> set[Signals]: ... def raise_signal(__signalnum: _SIGNUM) -> None: ... -if sys.version_info >= (3, 7): - def set_wakeup_fd(fd: int, *, warn_on_full_buffer: bool = ...) -> int: ... - -else: - def set_wakeup_fd(fd: int) -> int: ... +def set_wakeup_fd(fd: int, *, warn_on_full_buffer: bool = ...) -> int: ... if sys.version_info >= (3, 9): if sys.platform == "linux": diff --git a/stdlib/smtplib.pyi b/stdlib/smtplib.pyi index 65a85627b642..2e6eb0a22fbd 100644 --- a/stdlib/smtplib.pyi +++ b/stdlib/smtplib.pyi @@ -22,11 +22,9 @@ __all__ = [ "quotedata", "SMTP", "SMTP_SSL", + "SMTPNotSupportedError", ] -if sys.version_info >= (3, 7): - __all__ += ["SMTPNotSupportedError"] - _Reply: TypeAlias = tuple[int, bytes] _SendErrs: TypeAlias = dict[str, _Reply] # Should match source_address for socket.create_connection diff --git a/stdlib/socket.pyi b/stdlib/socket.pyi index 0b06e888aeb6..a0f5708bf806 100644 --- a/stdlib/socket.pyi +++ b/stdlib/socket.pyi @@ -138,14 +138,10 @@ if sys.version_info >= (3, 10): elif sys.platform != "darwin" and sys.platform != "win32": from _socket import IP_RECVTOS as IP_RECVTOS -if sys.version_info >= (3, 7): - from _socket import close as close +from _socket import TCP_KEEPINTVL as TCP_KEEPINTVL, close as close -if sys.platform != "win32" or sys.version_info >= (3, 7): - from _socket import TCP_KEEPINTVL as TCP_KEEPINTVL - - if sys.platform != "darwin": - from _socket import TCP_KEEPIDLE as TCP_KEEPIDLE +if sys.platform != "darwin": + from _socket import TCP_KEEPIDLE as TCP_KEEPIDLE if sys.platform != "win32" or sys.version_info >= (3, 8): from _socket import ( @@ -358,7 +354,7 @@ if sys.platform == "linux": TIPC_WITHDRAWN as TIPC_WITHDRAWN, TIPC_ZONE_SCOPE as TIPC_ZONE_SCOPE, ) -if sys.platform == "linux" and sys.version_info >= (3, 7): +if sys.platform == "linux": from _socket import ( CAN_ISOTP as CAN_ISOTP, IOCTL_VM_SOCKETS_GET_LOCAL_CID as IOCTL_VM_SOCKETS_GET_LOCAL_CID, @@ -370,7 +366,7 @@ if sys.platform == "linux" and sys.version_info >= (3, 7): VMADDR_CID_HOST as VMADDR_CID_HOST, VMADDR_PORT_ANY as VMADDR_PORT_ANY, ) -if sys.platform != "win32" and sys.version_info >= (3, 7): +if sys.platform != "win32": from _socket import TCP_NOTSENT_LOWAT as TCP_NOTSENT_LOWAT if sys.platform == "linux" and sys.version_info >= (3, 8): from _socket import ( @@ -473,8 +469,7 @@ class AddressFamily(IntEnum): AF_TIPC: int AF_ALG: int AF_NETLINK: int - if sys.version_info >= (3, 7): - AF_VSOCK: int + AF_VSOCK: int if sys.version_info >= (3, 8): AF_QIPCRTR: int if sys.platform != "win32" or sys.version_info >= (3, 9): @@ -523,8 +518,7 @@ if sys.platform == "linux": AF_TIPC = AddressFamily.AF_TIPC AF_ALG = AddressFamily.AF_ALG AF_NETLINK = AddressFamily.AF_NETLINK - if sys.version_info >= (3, 7): - AF_VSOCK = AddressFamily.AF_VSOCK + AF_VSOCK = AddressFamily.AF_VSOCK if sys.version_info >= (3, 8): AF_QIPCRTR = AddressFamily.AF_QIPCRTR @@ -563,9 +557,7 @@ class MsgFlag(IntFlag): if sys.platform != "darwin": MSG_BCAST: int MSG_MCAST: int - - if sys.platform != "win32" or sys.version_info >= (3, 7): - MSG_ERRQUEUE: int + MSG_ERRQUEUE: int if sys.platform != "win32" and sys.platform != "darwin": MSG_BTAG: int @@ -592,9 +584,7 @@ MSG_WAITALL = MsgFlag.MSG_WAITALL if sys.platform != "darwin": MSG_BCAST = MsgFlag.MSG_BCAST MSG_MCAST = MsgFlag.MSG_MCAST - - if sys.platform != "win32" or sys.version_info >= (3, 7): - MSG_ERRQUEUE = MsgFlag.MSG_ERRQUEUE + MSG_ERRQUEUE = MsgFlag.MSG_ERRQUEUE if sys.platform != "win32": MSG_DONTWAIT = MsgFlag.MSG_DONTWAIT diff --git a/stdlib/socketserver.pyi b/stdlib/socketserver.pyi index 8e2a24e7edfd..8c2b60d1fe9d 100644 --- a/stdlib/socketserver.pyi +++ b/stdlib/socketserver.pyi @@ -108,8 +108,7 @@ if sys.platform != "win32": timeout: float | None # undocumented active_children: set[int] | None # undocumented max_children: int # undocumented - if sys.version_info >= (3, 7): - block_on_close: bool + block_on_close: bool def collect_children(self, *, blocking: bool = ...) -> None: ... # undocumented def handle_timeout(self) -> None: ... # undocumented def service_actions(self) -> None: ... # undocumented @@ -118,8 +117,7 @@ if sys.platform != "win32": class ThreadingMixIn: daemon_threads: bool - if sys.version_info >= (3, 7): - block_on_close: bool + block_on_close: bool def process_request_thread(self, request: _RequestType, client_address: _AddressType) -> None: ... # undocumented def process_request(self, request: _RequestType, client_address: _AddressType) -> None: ... def server_close(self) -> None: ... diff --git a/stdlib/sqlite3/dbapi2.pyi b/stdlib/sqlite3/dbapi2.pyi index 3e98908db354..a1739b7bde38 100644 --- a/stdlib/sqlite3/dbapi2.pyi +++ b/stdlib/sqlite3/dbapi2.pyi @@ -48,13 +48,11 @@ SQLITE_CREATE_TEMP_TRIGGER: int SQLITE_CREATE_TEMP_VIEW: int SQLITE_CREATE_TRIGGER: int SQLITE_CREATE_VIEW: int -if sys.version_info >= (3, 7): - SQLITE_CREATE_VTABLE: int +SQLITE_CREATE_VTABLE: int SQLITE_DELETE: int SQLITE_DENY: int SQLITE_DETACH: int -if sys.version_info >= (3, 7): - SQLITE_DONE: int +SQLITE_DONE: int SQLITE_DROP_INDEX: int SQLITE_DROP_TABLE: int SQLITE_DROP_TEMP_INDEX: int @@ -63,9 +61,8 @@ SQLITE_DROP_TEMP_TRIGGER: int SQLITE_DROP_TEMP_VIEW: int SQLITE_DROP_TRIGGER: int SQLITE_DROP_VIEW: int -if sys.version_info >= (3, 7): - SQLITE_DROP_VTABLE: int - SQLITE_FUNCTION: int +SQLITE_DROP_VTABLE: int +SQLITE_FUNCTION: int SQLITE_IGNORE: int SQLITE_INSERT: int SQLITE_OK: int @@ -85,9 +82,8 @@ if sys.version_info >= (3, 11): SQLITE_PRAGMA: int SQLITE_READ: int SQLITE_REINDEX: int -if sys.version_info >= (3, 7): - SQLITE_RECURSIVE: int - SQLITE_SAVEPOINT: int +SQLITE_RECURSIVE: int +SQLITE_SAVEPOINT: int SQLITE_SELECT: int SQLITE_TRANSACTION: int SQLITE_UPDATE: int @@ -207,14 +203,8 @@ def adapt(__obj: Any, __proto: Any) -> Any: ... @overload def adapt(__obj: Any, __proto: Any, __alt: _T) -> Any | _T: ... def complete_statement(statement: str) -> bool: ... - -if sys.version_info >= (3, 7): - _DatabaseArg: TypeAlias = StrOrBytesPath -else: - _DatabaseArg: TypeAlias = bytes | str - def connect( - database: _DatabaseArg, + database: StrOrBytesPath, timeout: float = ..., detect_types: int = ..., isolation_level: str | None = ..., @@ -288,7 +278,7 @@ class Connection: text_factory: Any def __init__( self, - database: _DatabaseArg, + database: StrOrBytesPath, timeout: float = ..., detect_types: int = ..., isolation_level: str | None = ..., @@ -347,16 +337,15 @@ class Connection: # without sqlite3 loadable extension support. see footnotes https://docs.python.org/3/library/sqlite3.html#f1 def enable_load_extension(self, __enabled: bool) -> None: ... def load_extension(self, __name: str) -> None: ... - if sys.version_info >= (3, 7): - def backup( - self, - target: Connection, - *, - pages: int = ..., - progress: Callable[[int, int, int], object] | None = ..., - name: str = ..., - sleep: float = ..., - ) -> None: ... + def backup( + self, + target: Connection, + *, + pages: int = ..., + progress: Callable[[int, int, int], object] | None = ..., + name: str = ..., + sleep: float = ..., + ) -> None: ... if sys.version_info >= (3, 11): def setlimit(self, __category: int, __limit: int) -> int: ... def getlimit(self, __category: int) -> int: ... diff --git a/stdlib/sre_constants.pyi b/stdlib/sre_constants.pyi index 20a8437ed007..e7344fae3798 100644 --- a/stdlib/sre_constants.pyi +++ b/stdlib/sre_constants.pyi @@ -23,9 +23,8 @@ OPCODES: list[_NamedIntConstant] ATCODES: list[_NamedIntConstant] CHCODES: list[_NamedIntConstant] OP_IGNORE: dict[_NamedIntConstant, _NamedIntConstant] -if sys.version_info >= (3, 7): - OP_LOCALE_IGNORE: dict[_NamedIntConstant, _NamedIntConstant] - OP_UNICODE_IGNORE: dict[_NamedIntConstant, _NamedIntConstant] +OP_LOCALE_IGNORE: dict[_NamedIntConstant, _NamedIntConstant] +OP_UNICODE_IGNORE: dict[_NamedIntConstant, _NamedIntConstant] AT_MULTILINE: dict[_NamedIntConstant, _NamedIntConstant] AT_LOCALE: dict[_NamedIntConstant, _NamedIntConstant] AT_UNICODE: dict[_NamedIntConstant, _NamedIntConstant] @@ -80,18 +79,15 @@ REPEAT: _NamedIntConstant REPEAT_ONE: _NamedIntConstant SUBPATTERN: _NamedIntConstant MIN_REPEAT_ONE: _NamedIntConstant -if sys.version_info >= (3, 7): - RANGE_UNI_IGNORE: _NamedIntConstant - GROUPREF_LOC_IGNORE: _NamedIntConstant - GROUPREF_UNI_IGNORE: _NamedIntConstant - IN_LOC_IGNORE: _NamedIntConstant - IN_UNI_IGNORE: _NamedIntConstant - LITERAL_LOC_IGNORE: _NamedIntConstant - LITERAL_UNI_IGNORE: _NamedIntConstant - NOT_LITERAL_LOC_IGNORE: _NamedIntConstant - NOT_LITERAL_UNI_IGNORE: _NamedIntConstant -else: - RANGE_IGNORE: _NamedIntConstant +RANGE_UNI_IGNORE: _NamedIntConstant +GROUPREF_LOC_IGNORE: _NamedIntConstant +GROUPREF_UNI_IGNORE: _NamedIntConstant +IN_LOC_IGNORE: _NamedIntConstant +IN_UNI_IGNORE: _NamedIntConstant +LITERAL_LOC_IGNORE: _NamedIntConstant +LITERAL_UNI_IGNORE: _NamedIntConstant +NOT_LITERAL_LOC_IGNORE: _NamedIntConstant +NOT_LITERAL_UNI_IGNORE: _NamedIntConstant MIN_REPEAT: _NamedIntConstant MAX_REPEAT: _NamedIntConstant diff --git a/stdlib/sre_parse.pyi b/stdlib/sre_parse.pyi index 1e903028ba7e..ad05922392f3 100644 --- a/stdlib/sre_parse.pyi +++ b/stdlib/sre_parse.pyi @@ -15,8 +15,7 @@ WHITESPACE: frozenset[str] ESCAPES: dict[str, tuple[_NIC, int]] CATEGORIES: dict[str, tuple[_NIC, _NIC] | tuple[_NIC, list[tuple[_NIC, _NIC]]]] FLAGS: dict[str, int] -if sys.version_info >= (3, 7): - TYPE_FLAGS: int +TYPE_FLAGS: int GLOBAL_FLAGS: int if sys.version_info < (3, 11): diff --git a/stdlib/ssl.pyi b/stdlib/ssl.pyi index 9f0420029258..09c8d07780a7 100644 --- a/stdlib/ssl.pyi +++ b/stdlib/ssl.pyi @@ -38,13 +38,11 @@ class SSLWantWriteError(SSLError): ... class SSLSyscallError(SSLError): ... class SSLEOFError(SSLError): ... -if sys.version_info >= (3, 7): - class SSLCertVerificationError(SSLError, ValueError): - verify_code: int - verify_message: str - CertificateError = SSLCertVerificationError -else: - class CertificateError(ValueError): ... +class SSLCertVerificationError(SSLError, ValueError): + verify_code: int + verify_message: str + +CertificateError = SSLCertVerificationError def wrap_socket( sock: socket.socket, @@ -65,34 +63,18 @@ def create_default_context( capath: StrOrBytesPath | None = ..., cadata: str | bytes | None = ..., ) -> SSLContext: ... - -if sys.version_info >= (3, 7): - def _create_unverified_context( - protocol: int = ..., - *, - cert_reqs: int = ..., - check_hostname: bool = ..., - purpose: Purpose = ..., - certfile: StrOrBytesPath | None = ..., - keyfile: StrOrBytesPath | None = ..., - cafile: StrOrBytesPath | None = ..., - capath: StrOrBytesPath | None = ..., - cadata: str | bytes | None = ..., - ) -> SSLContext: ... - -else: - def _create_unverified_context( - protocol: int = ..., - *, - cert_reqs: int | None = ..., - check_hostname: bool = ..., - purpose: Purpose = ..., - certfile: StrOrBytesPath | None = ..., - keyfile: StrOrBytesPath | None = ..., - cafile: StrOrBytesPath | None = ..., - capath: StrOrBytesPath | None = ..., - cadata: str | bytes | None = ..., - ) -> SSLContext: ... +def _create_unverified_context( + protocol: int = ..., + *, + cert_reqs: int = ..., + check_hostname: bool = ..., + purpose: Purpose = ..., + certfile: StrOrBytesPath | None = ..., + keyfile: StrOrBytesPath | None = ..., + cafile: StrOrBytesPath | None = ..., + capath: StrOrBytesPath | None = ..., + cadata: str | bytes | None = ..., +) -> SSLContext: ... _create_default_https_context: Callable[..., SSLContext] @@ -192,8 +174,7 @@ class Options(enum.IntFlag): OP_SINGLE_ECDH_USE: int OP_NO_COMPRESSION: int OP_NO_TICKET: int - if sys.version_info >= (3, 7): - OP_NO_RENEGOTIATION: int + OP_NO_RENEGOTIATION: int if sys.version_info >= (3, 8): OP_ENABLE_MIDDLEBOX_COMPAT: int @@ -209,18 +190,16 @@ OP_SINGLE_DH_USE: Options OP_SINGLE_ECDH_USE: Options OP_NO_COMPRESSION: Options OP_NO_TICKET: Options -if sys.version_info >= (3, 7): - OP_NO_RENEGOTIATION: Options +OP_NO_RENEGOTIATION: Options if sys.version_info >= (3, 8): OP_ENABLE_MIDDLEBOX_COMPAT: Options -if sys.version_info >= (3, 7): - HAS_NEVER_CHECK_COMMON_NAME: bool - HAS_SSLv2: bool - HAS_SSLv3: bool - HAS_TLSv1: bool - HAS_TLSv1_1: bool - HAS_TLSv1_2: bool +HAS_NEVER_CHECK_COMMON_NAME: bool +HAS_SSLv2: bool +HAS_SSLv3: bool +HAS_TLSv1: bool +HAS_TLSv1_1: bool +HAS_TLSv1_2: bool HAS_TLSv1_3: bool HAS_ALPN: bool HAS_ECDH: bool @@ -310,31 +289,7 @@ class SSLSocket(socket.socket): session: SSLSession | None @property def session_reused(self) -> bool | None: ... - if sys.version_info >= (3, 7): - def __init__(self, *args: Any, **kwargs: Any) -> None: ... - else: - def __init__( - self, - sock: socket.socket | None = ..., - keyfile: str | None = ..., - certfile: str | None = ..., - server_side: bool = ..., - cert_reqs: int = ..., - ssl_version: int = ..., - ca_certs: str | None = ..., - do_handshake_on_connect: bool = ..., - family: int = ..., - type: int = ..., - proto: int = ..., - fileno: int | None = ..., - suppress_ragged_eofs: bool = ..., - npn_protocols: Iterable[str] | None = ..., - ciphers: str | None = ..., - server_hostname: str | None = ..., - _context: SSLContext | None = ..., - _session: Any | None = ..., - ) -> None: ... - + def __init__(self, *args: Any, **kwargs: Any) -> None: ... def connect(self, addr: socket._Address | bytes) -> None: ... def connect_ex(self, addr: socket._Address | bytes) -> int: ... def recv(self, buflen: int = ..., flags: int = ...) -> bytes: ... @@ -372,15 +327,14 @@ class SSLSocket(socket.socket): if sys.version_info >= (3, 8): def verify_client_post_handshake(self) -> None: ... -if sys.version_info >= (3, 7): - class TLSVersion(enum.IntEnum): - MINIMUM_SUPPORTED: int - MAXIMUM_SUPPORTED: int - SSLv3: int - TLSv1: int - TLSv1_1: int - TLSv1_2: int - TLSv1_3: int +class TLSVersion(enum.IntEnum): + MINIMUM_SUPPORTED: int + MAXIMUM_SUPPORTED: int + SSLv3: int + TLSv1: int + TLSv1_1: int + TLSv1_2: int + TLSv1_3: int class SSLContext: check_hostname: bool @@ -389,16 +343,15 @@ class SSLContext: verify_mode: VerifyMode @property def protocol(self) -> _SSLMethod: ... - if sys.version_info >= (3, 7): - hostname_checks_common_name: bool - maximum_version: TLSVersion - minimum_version: TLSVersion - sni_callback: Callable[[SSLObject, str, SSLContext], None | int] | None - # The following two attributes have class-level defaults. - # However, the docs explicitly state that it's OK to override these attributes on instances, - # so making these ClassVars wouldn't be appropriate - sslobject_class: type[SSLObject] - sslsocket_class: type[SSLSocket] + hostname_checks_common_name: bool + maximum_version: TLSVersion + minimum_version: TLSVersion + sni_callback: Callable[[SSLObject, str, SSLContext], None | int] | None + # The following two attributes have class-level defaults. + # However, the docs explicitly state that it's OK to override these attributes on instances, + # so making these ClassVars wouldn't be appropriate + sslobject_class: type[SSLObject] + sslsocket_class: type[SSLSocket] if sys.version_info >= (3, 8): keylog_filename: str post_handshake_auth: bool @@ -423,11 +376,7 @@ class SSLContext: def set_ciphers(self, __cipherlist: str) -> None: ... def set_alpn_protocols(self, alpn_protocols: Iterable[str]) -> None: ... def set_npn_protocols(self, npn_protocols: Iterable[str]) -> None: ... - if sys.version_info >= (3, 7): - def set_servername_callback(self, server_name_callback: _SrvnmeCbType | None) -> None: ... - else: - def set_servername_callback(self, __method: _SrvnmeCbType | None) -> None: ... - + def set_servername_callback(self, server_name_callback: _SrvnmeCbType | None) -> None: ... def load_dh_params(self, __path: str) -> None: ... def set_ecdh_curve(self, __name: str) -> None: ... def wrap_socket( @@ -458,11 +407,7 @@ class SSLObject: session: SSLSession | None @property def session_reused(self) -> bool: ... - if sys.version_info >= (3, 7): - def __init__(self, *args: Any, **kwargs: Any) -> None: ... - else: - def __init__(self, sslobj: Any, owner: SSLSocket | SSLObject | None = ..., session: Any | None = ...) -> None: ... - + def __init__(self, *args: Any, **kwargs: Any) -> None: ... def read(self, len: int = ..., buffer: bytearray | None = ...) -> bytes: ... def write(self, data: bytes) -> int: ... @overload diff --git a/stdlib/struct.pyi b/stdlib/struct.pyi index 59c66ad2f167..f7eff2b76f14 100644 --- a/stdlib/struct.pyi +++ b/stdlib/struct.pyi @@ -1,4 +1,3 @@ -import sys from _typeshed import ReadableBuffer, WriteableBuffer from collections.abc import Iterator from typing import Any @@ -15,10 +14,7 @@ def iter_unpack(__format: str | bytes, __buffer: ReadableBuffer) -> Iterator[tup def calcsize(__format: str | bytes) -> int: ... class Struct: - if sys.version_info >= (3, 7): - format: str - else: - format: bytes + format: str size: int def __init__(self, format: str | bytes) -> None: ... def pack(self, *v: Any) -> bytes: ... diff --git a/stdlib/subprocess.pyi b/stdlib/subprocess.pyi index 470069a96a80..0fa9d888c035 100644 --- a/stdlib/subprocess.pyi +++ b/stdlib/subprocess.pyi @@ -36,22 +36,18 @@ if sys.platform == "win32": "STD_INPUT_HANDLE", "STD_OUTPUT_HANDLE", "SW_HIDE", + "ABOVE_NORMAL_PRIORITY_CLASS", + "BELOW_NORMAL_PRIORITY_CLASS", + "CREATE_BREAKAWAY_FROM_JOB", + "CREATE_DEFAULT_ERROR_MODE", + "CREATE_NO_WINDOW", + "DETACHED_PROCESS", + "HIGH_PRIORITY_CLASS", + "IDLE_PRIORITY_CLASS", + "NORMAL_PRIORITY_CLASS", + "REALTIME_PRIORITY_CLASS", ] - if sys.version_info >= (3, 7): - __all__ += [ - "ABOVE_NORMAL_PRIORITY_CLASS", - "BELOW_NORMAL_PRIORITY_CLASS", - "CREATE_BREAKAWAY_FROM_JOB", - "CREATE_DEFAULT_ERROR_MODE", - "CREATE_NO_WINDOW", - "DETACHED_PROCESS", - "HIGH_PRIORITY_CLASS", - "IDLE_PRIORITY_CLASS", - "NORMAL_PRIORITY_CLASS", - "REALTIME_PRIORITY_CLASS", - ] - # We prefer to annotate inputs to methods (eg subprocess.check_call) with these # union types. # For outputs we use laborious literal based overloads to try to determine @@ -707,7 +703,7 @@ elif sys.version_info >= (3, 9): umask: int = ..., ) -> CompletedProcess[Any]: ... -elif sys.version_info >= (3, 7): +else: # Nearly the same args as for 3.6, except for capture_output and text @overload def run( @@ -879,140 +875,6 @@ elif sys.version_info >= (3, 7): timeout: float | None = ..., ) -> CompletedProcess[Any]: ... -else: - # Nearly same args as Popen.__init__ except for timeout, input, and check - @overload - def run( - args: _CMD, - bufsize: int = ..., - executable: StrOrBytesPath | None = ..., - stdin: _FILE = ..., - stdout: _FILE = ..., - stderr: _FILE = ..., - preexec_fn: Callable[[], Any] | None = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: StrOrBytesPath | None = ..., - env: _ENV | None = ..., - universal_newlines: bool = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - *, - check: bool = ..., - encoding: str, - errors: str | None = ..., - input: str | None = ..., - timeout: float | None = ..., - ) -> CompletedProcess[str]: ... - @overload - def run( - args: _CMD, - bufsize: int = ..., - executable: StrOrBytesPath | None = ..., - stdin: _FILE = ..., - stdout: _FILE = ..., - stderr: _FILE = ..., - preexec_fn: Callable[[], Any] | None = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: StrOrBytesPath | None = ..., - env: _ENV | None = ..., - universal_newlines: bool = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - *, - check: bool = ..., - encoding: str | None = ..., - errors: str, - input: str | None = ..., - timeout: float | None = ..., - ) -> CompletedProcess[str]: ... - @overload - def run( - args: _CMD, - bufsize: int = ..., - executable: StrOrBytesPath | None = ..., - stdin: _FILE = ..., - stdout: _FILE = ..., - stderr: _FILE = ..., - preexec_fn: Callable[[], Any] | None = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: StrOrBytesPath | None = ..., - env: _ENV | None = ..., - *, - universal_newlines: Literal[True], - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - # where the *real* keyword only args start - check: bool = ..., - encoding: str | None = ..., - errors: str | None = ..., - input: str | None = ..., - timeout: float | None = ..., - ) -> CompletedProcess[str]: ... - @overload - def run( - args: _CMD, - bufsize: int = ..., - executable: StrOrBytesPath | None = ..., - stdin: _FILE = ..., - stdout: _FILE = ..., - stderr: _FILE = ..., - preexec_fn: Callable[[], Any] | None = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: StrOrBytesPath | None = ..., - env: _ENV | None = ..., - universal_newlines: Literal[False] = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - *, - check: bool = ..., - encoding: None = ..., - errors: None = ..., - input: bytes | None = ..., - timeout: float | None = ..., - ) -> CompletedProcess[bytes]: ... - @overload - def run( - args: _CMD, - bufsize: int = ..., - executable: StrOrBytesPath | None = ..., - stdin: _FILE = ..., - stdout: _FILE = ..., - stderr: _FILE = ..., - preexec_fn: Callable[[], Any] | None = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: StrOrBytesPath | None = ..., - env: _ENV | None = ..., - universal_newlines: bool = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - *, - check: bool = ..., - encoding: str | None = ..., - errors: str | None = ..., - input: _TXT | None = ..., - timeout: float | None = ..., - ) -> CompletedProcess[Any]: ... - # Same args as Popen.__init__ if sys.version_info >= (3, 11): # 3.11 adds "process_group" argument @@ -1104,31 +966,6 @@ elif sys.version_info >= (3, 9): umask: int = ..., ) -> int: ... -elif sys.version_info >= (3, 7): - # 3.7 adds the "text" argument - def call( - args: _CMD, - bufsize: int = ..., - executable: StrOrBytesPath | None = ..., - stdin: _FILE = ..., - stdout: _FILE = ..., - stderr: _FILE = ..., - preexec_fn: Callable[[], Any] | None = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: StrOrBytesPath | None = ..., - env: _ENV | None = ..., - universal_newlines: bool = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - *, - timeout: float | None = ..., - text: bool | None = ..., - ) -> int: ... - else: def call( args: _CMD, @@ -1150,6 +987,7 @@ else: pass_fds: Any = ..., *, timeout: float | None = ..., + text: bool | None = ..., ) -> int: ... # Same args as Popen.__init__ @@ -1243,8 +1081,7 @@ elif sys.version_info >= (3, 9): umask: int = ..., ) -> int: ... -elif sys.version_info >= (3, 7): - # 3.7 adds the "text" argument +else: def check_call( args: _CMD, bufsize: int = ..., @@ -1268,28 +1105,6 @@ elif sys.version_info >= (3, 7): text: bool | None = ..., ) -> int: ... -else: - def check_call( - args: _CMD, - bufsize: int = ..., - executable: StrOrBytesPath = ..., - stdin: _FILE = ..., - stdout: _FILE = ..., - stderr: _FILE = ..., - preexec_fn: Callable[[], Any] | None = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: StrOrBytesPath | None = ..., - env: _ENV | None = ..., - universal_newlines: bool = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - timeout: float | None = ..., - ) -> int: ... - if sys.version_info >= (3, 11): # 3.11 adds "process_group" argument @overload @@ -1842,8 +1657,7 @@ elif sys.version_info >= (3, 9): umask: int = ..., ) -> Any: ... # morally: -> _TXT -elif sys.version_info >= (3, 7): - # 3.7 added text +else: @overload def check_output( args: _CMD, @@ -1996,128 +1810,6 @@ elif sys.version_info >= (3, 7): text: bool | None = ..., ) -> Any: ... # morally: -> _TXT -else: - @overload - def check_output( - args: _CMD, - bufsize: int = ..., - executable: StrOrBytesPath | None = ..., - stdin: _FILE = ..., - stderr: _FILE = ..., - preexec_fn: Callable[[], Any] | None = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: StrOrBytesPath | None = ..., - env: _ENV | None = ..., - universal_newlines: bool = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - *, - timeout: float | None = ..., - input: _TXT | None = ..., - encoding: str, - errors: str | None = ..., - ) -> str: ... - @overload - def check_output( - args: _CMD, - bufsize: int = ..., - executable: StrOrBytesPath | None = ..., - stdin: _FILE = ..., - stderr: _FILE = ..., - preexec_fn: Callable[[], Any] | None = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: StrOrBytesPath | None = ..., - env: _ENV | None = ..., - universal_newlines: bool = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - *, - timeout: float | None = ..., - input: _TXT | None = ..., - encoding: str | None = ..., - errors: str, - ) -> str: ... - @overload - def check_output( - args: _CMD, - bufsize: int = ..., - executable: StrOrBytesPath | None = ..., - stdin: _FILE = ..., - stderr: _FILE = ..., - preexec_fn: Callable[[], Any] | None = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: StrOrBytesPath | None = ..., - env: _ENV | None = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - *, - universal_newlines: Literal[True], - timeout: float | None = ..., - input: _TXT | None = ..., - encoding: str | None = ..., - errors: str | None = ..., - ) -> str: ... - @overload - def check_output( - args: _CMD, - bufsize: int = ..., - executable: StrOrBytesPath | None = ..., - stdin: _FILE = ..., - stderr: _FILE = ..., - preexec_fn: Callable[[], Any] | None = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: StrOrBytesPath | None = ..., - env: _ENV | None = ..., - universal_newlines: Literal[False] = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - *, - timeout: float | None = ..., - input: _TXT | None = ..., - encoding: None = ..., - errors: None = ..., - ) -> bytes: ... - @overload - def check_output( - args: _CMD, - bufsize: int = ..., - executable: StrOrBytesPath | None = ..., - stdin: _FILE = ..., - stderr: _FILE = ..., - preexec_fn: Callable[[], Any] | None = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: StrOrBytesPath | None = ..., - env: _ENV | None = ..., - universal_newlines: bool = ..., - startupinfo: Any = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - *, - timeout: float | None = ..., - input: _TXT | None = ..., - encoding: str | None = ..., - errors: str | None = ..., - ) -> Any: ... # morally: -> _TXT - PIPE: int STDOUT: int DEVNULL: int @@ -2704,8 +2396,7 @@ class Popen(Generic[AnyStr]): extra_groups: Iterable[str | int] | None = ..., umask: int = ..., ) -> None: ... - elif sys.version_info >= (3, 7): - # text is added in 3.7 + else: @overload def __init__( self: Popen[str], @@ -2857,134 +2548,9 @@ class Popen(Generic[AnyStr]): encoding: str | None = ..., errors: str | None = ..., ) -> None: ... - else: - @overload - def __init__( - self: Popen[str], - args: _CMD, - bufsize: int = ..., - executable: StrOrBytesPath | None = ..., - stdin: _FILE | None = ..., - stdout: _FILE | None = ..., - stderr: _FILE | None = ..., - preexec_fn: Callable[[], Any] | None = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: StrOrBytesPath | None = ..., - env: _ENV | None = ..., - universal_newlines: bool = ..., - startupinfo: Any | None = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - *, - encoding: str, - errors: str | None = ..., - ) -> None: ... - @overload - def __init__( - self: Popen[str], - args: _CMD, - bufsize: int = ..., - executable: StrOrBytesPath | None = ..., - stdin: _FILE | None = ..., - stdout: _FILE | None = ..., - stderr: _FILE | None = ..., - preexec_fn: Callable[[], Any] | None = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: StrOrBytesPath | None = ..., - env: _ENV | None = ..., - universal_newlines: bool = ..., - startupinfo: Any | None = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - *, - encoding: str | None = ..., - errors: str, - ) -> None: ... - @overload - def __init__( - self: Popen[str], - args: _CMD, - bufsize: int = ..., - executable: StrOrBytesPath | None = ..., - stdin: _FILE | None = ..., - stdout: _FILE | None = ..., - stderr: _FILE | None = ..., - preexec_fn: Callable[[], Any] | None = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: StrOrBytesPath | None = ..., - env: _ENV | None = ..., - *, - universal_newlines: Literal[True], - startupinfo: Any | None = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - # where the *real* keyword only args start - encoding: str | None = ..., - errors: str | None = ..., - ) -> None: ... - @overload - def __init__( - self: Popen[bytes], - args: _CMD, - bufsize: int = ..., - executable: StrOrBytesPath | None = ..., - stdin: _FILE | None = ..., - stdout: _FILE | None = ..., - stderr: _FILE | None = ..., - preexec_fn: Callable[[], Any] | None = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: StrOrBytesPath | None = ..., - env: _ENV | None = ..., - universal_newlines: Literal[False] = ..., - startupinfo: Any | None = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - *, - encoding: None = ..., - errors: None = ..., - ) -> None: ... - @overload - def __init__( - self: Popen[Any], - args: _CMD, - bufsize: int = ..., - executable: StrOrBytesPath | None = ..., - stdin: _FILE | None = ..., - stdout: _FILE | None = ..., - stderr: _FILE | None = ..., - preexec_fn: Callable[[], Any] | None = ..., - close_fds: bool = ..., - shell: bool = ..., - cwd: StrOrBytesPath | None = ..., - env: _ENV | None = ..., - universal_newlines: bool = ..., - startupinfo: Any | None = ..., - creationflags: int = ..., - restore_signals: bool = ..., - start_new_session: bool = ..., - pass_fds: Any = ..., - *, - encoding: str | None = ..., - errors: str | None = ..., - ) -> None: ... def poll(self) -> int | None: ... - if sys.version_info >= (3, 7): - def wait(self, timeout: float | None = ...) -> int: ... - else: - def wait(self, timeout: float | None = ..., endtime: float | None = ...) -> int: ... + def wait(self, timeout: float | None = ...) -> int: ... # Return str/bytes def communicate( self, @@ -3019,27 +2585,35 @@ else: if sys.platform == "win32": class STARTUPINFO: - if sys.version_info >= (3, 7): - def __init__( - self, - *, - dwFlags: int = ..., - hStdInput: Any | None = ..., - hStdOutput: Any | None = ..., - hStdError: Any | None = ..., - wShowWindow: int = ..., - lpAttributeList: Mapping[str, Any] | None = ..., - ) -> None: ... + def __init__( + self, + *, + dwFlags: int = ..., + hStdInput: Any | None = ..., + hStdOutput: Any | None = ..., + hStdError: Any | None = ..., + wShowWindow: int = ..., + lpAttributeList: Mapping[str, Any] | None = ..., + ) -> None: ... dwFlags: int hStdInput: Any | None hStdOutput: Any | None hStdError: Any | None wShowWindow: int - if sys.version_info >= (3, 7): - lpAttributeList: Mapping[str, Any] + lpAttributeList: Mapping[str, Any] from _winapi import ( + ABOVE_NORMAL_PRIORITY_CLASS as ABOVE_NORMAL_PRIORITY_CLASS, + BELOW_NORMAL_PRIORITY_CLASS as BELOW_NORMAL_PRIORITY_CLASS, + CREATE_BREAKAWAY_FROM_JOB as CREATE_BREAKAWAY_FROM_JOB, + CREATE_DEFAULT_ERROR_MODE as CREATE_DEFAULT_ERROR_MODE, CREATE_NEW_CONSOLE as CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP as CREATE_NEW_PROCESS_GROUP, + CREATE_NO_WINDOW as CREATE_NO_WINDOW, + DETACHED_PROCESS as DETACHED_PROCESS, + HIGH_PRIORITY_CLASS as HIGH_PRIORITY_CLASS, + IDLE_PRIORITY_CLASS as IDLE_PRIORITY_CLASS, + NORMAL_PRIORITY_CLASS as NORMAL_PRIORITY_CLASS, + REALTIME_PRIORITY_CLASS as REALTIME_PRIORITY_CLASS, STARTF_USESHOWWINDOW as STARTF_USESHOWWINDOW, STARTF_USESTDHANDLES as STARTF_USESTDHANDLES, STD_ERROR_HANDLE as STD_ERROR_HANDLE, @@ -3047,17 +2621,3 @@ if sys.platform == "win32": STD_OUTPUT_HANDLE as STD_OUTPUT_HANDLE, SW_HIDE as SW_HIDE, ) - - if sys.version_info >= (3, 7): - from _winapi import ( - ABOVE_NORMAL_PRIORITY_CLASS as ABOVE_NORMAL_PRIORITY_CLASS, - BELOW_NORMAL_PRIORITY_CLASS as BELOW_NORMAL_PRIORITY_CLASS, - CREATE_BREAKAWAY_FROM_JOB as CREATE_BREAKAWAY_FROM_JOB, - CREATE_DEFAULT_ERROR_MODE as CREATE_DEFAULT_ERROR_MODE, - CREATE_NO_WINDOW as CREATE_NO_WINDOW, - DETACHED_PROCESS as DETACHED_PROCESS, - HIGH_PRIORITY_CLASS as HIGH_PRIORITY_CLASS, - IDLE_PRIORITY_CLASS as IDLE_PRIORITY_CLASS, - NORMAL_PRIORITY_CLASS as NORMAL_PRIORITY_CLASS, - REALTIME_PRIORITY_CLASS as REALTIME_PRIORITY_CLASS, - ) diff --git a/stdlib/symbol.pyi b/stdlib/symbol.pyi index 234c814b55b5..bb6660374d16 100644 --- a/stdlib/symbol.pyi +++ b/stdlib/symbol.pyi @@ -86,8 +86,7 @@ comp_if: int encoding_decl: int yield_expr: int yield_arg: int -if sys.version_info >= (3, 7): - sync_comp_for: int +sync_comp_for: int if sys.version_info >= (3, 8): func_body_suite: int func_type: int diff --git a/stdlib/sys.pyi b/stdlib/sys.pyi index ef8dc085c7af..9b113e5ef674 100644 --- a/stdlib/sys.pyi +++ b/stdlib/sys.pyi @@ -81,10 +81,8 @@ flags: _flags if sys.version_info >= (3, 10): _FlagTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, bool, int, int] -elif sys.version_info >= (3, 7): - _FlagTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, bool, int] else: - _FlagTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int, int, int, int, int] + _FlagTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, bool, int] @final class _flags(_UninstantiableStructseq, _FlagTuple): @@ -114,11 +112,10 @@ class _flags(_UninstantiableStructseq, _FlagTuple): def hash_randomization(self) -> int: ... @property def isolated(self) -> int: ... - if sys.version_info >= (3, 7): - @property - def dev_mode(self) -> bool: ... - @property - def utf8_mode(self) -> int: ... + @property + def dev_mode(self) -> bool: ... + @property + def utf8_mode(self) -> int: ... if sys.version_info >= (3, 10): @property def warn_default_encoding(self) -> int: ... # undocumented @@ -276,9 +273,9 @@ if sys.platform == "win32": def intern(__string: str) -> str: ... def is_finalizing() -> bool: ... -if sys.version_info >= (3, 7): - __breakpointhook__: Any # contains the original value of breakpointhook - def breakpointhook(*args: Any, **kwargs: Any) -> Any: ... +__breakpointhook__: Any # contains the original value of breakpointhook + +def breakpointhook(*args: Any, **kwargs: Any) -> Any: ... if sys.platform != "win32": def setdlopenflags(__flags: int) -> None: ... @@ -323,9 +320,8 @@ def set_asyncgen_hooks(firstiter: _AsyncgenHook = ..., finalizer: _AsyncgenHook if sys.platform == "win32": def _enablelegacywindowsfsencoding() -> None: ... -if sys.version_info >= (3, 7): - def get_coroutine_origin_tracking_depth() -> int: ... - def set_coroutine_origin_tracking_depth(depth: int) -> None: ... +def get_coroutine_origin_tracking_depth() -> int: ... +def set_coroutine_origin_tracking_depth(depth: int) -> None: ... if sys.version_info < (3, 8): _CoroWrapper: TypeAlias = Callable[[Coroutine[Any, Any, Any]], Any] diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 87c57311aa99..cf74899a8fb4 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -294,26 +294,14 @@ class TarFile: def chown(self, tarinfo: TarInfo, targetpath: StrOrBytesPath, numeric_owner: bool) -> None: ... # undocumented def chmod(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented def utime(self, tarinfo: TarInfo, targetpath: StrOrBytesPath) -> None: ... # undocumented - if sys.version_info >= (3, 7): - def add( - self, - name: StrPath, - arcname: StrPath | None = ..., - recursive: bool = ..., - *, - filter: Callable[[TarInfo], TarInfo | None] | None = ..., - ) -> None: ... - else: - def add( - self, - name: StrPath, - arcname: StrPath | None = ..., - recursive: bool = ..., - exclude: Callable[[str], bool] | None = ..., - *, - filter: Callable[[TarInfo], TarInfo | None] | None = ..., - ) -> None: ... - + def add( + self, + name: StrPath, + arcname: StrPath | None = ..., + recursive: bool = ..., + *, + filter: Callable[[TarInfo], TarInfo | None] | None = ..., + ) -> None: ... def addfile(self, tarinfo: TarInfo, fileobj: IO[bytes] | None = ...) -> None: ... def gettarinfo( self, name: StrOrBytesPath | None = ..., arcname: str | None = ..., fileobj: IO[bytes] | None = ... diff --git a/stdlib/time.pyi b/stdlib/time.pyi index cceb7c8ca874..035d78934f3a 100644 --- a/stdlib/time.pyi +++ b/stdlib/time.pyi @@ -10,12 +10,11 @@ daylight: int timezone: int tzname: tuple[str, str] -if sys.version_info >= (3, 7): - if sys.platform == "linux": - CLOCK_BOOTTIME: int - if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin": - CLOCK_PROF: int # FreeBSD, NetBSD, OpenBSD - CLOCK_UPTIME: int # FreeBSD, OpenBSD +if sys.platform == "linux": + CLOCK_BOOTTIME: int +if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin": + CLOCK_PROF: int # FreeBSD, NetBSD, OpenBSD + CLOCK_UPTIME: int # FreeBSD, OpenBSD if sys.platform != "win32": CLOCK_MONOTONIC: int @@ -97,17 +96,16 @@ if sys.platform != "win32": def clock_gettime(clk_id: int) -> float: ... # Unix only def clock_settime(clk_id: int, time: float) -> None: ... # Unix only -if sys.version_info >= (3, 7): - if sys.platform != "win32": - def clock_gettime_ns(clock_id: int) -> int: ... - def clock_settime_ns(clock_id: int, time: int) -> int: ... - - if sys.platform == "linux": - def pthread_getcpuclockid(thread_id: int) -> int: ... - - def monotonic_ns() -> int: ... - def perf_counter_ns() -> int: ... - def process_time_ns() -> int: ... - def time_ns() -> int: ... - def thread_time() -> float: ... - def thread_time_ns() -> int: ... +if sys.platform != "win32": + def clock_gettime_ns(clock_id: int) -> int: ... + def clock_settime_ns(clock_id: int, time: int) -> int: ... + +if sys.platform == "linux": + def pthread_getcpuclockid(thread_id: int) -> int: ... + +def monotonic_ns() -> int: ... +def perf_counter_ns() -> int: ... +def process_time_ns() -> int: ... +def time_ns() -> int: ... +def thread_time() -> float: ... +def thread_time_ns() -> int: ... diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index 0fe94ad30ff5..81077200289f 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -31,11 +31,9 @@ __all__ = [ "OptionMenu", "tclobjs_to_py", "setup_master", + "Spinbox", ] -if sys.version_info >= (3, 7): - __all__ += ["Spinbox"] - def tclobjs_to_py(adict: dict[Any, Any]) -> dict[Any, Any]: ... def setup_master(master: Any | None = ...): ... @@ -853,71 +851,70 @@ class Sizegrip(Widget): def configure(self, cnf: str) -> tuple[str, str, str, Any, Any]: ... config = configure -if sys.version_info >= (3, 7): - class Spinbox(Entry): - def __init__( - self, - master: tkinter.Misc | None = ..., - *, - background: tkinter._Color = ..., # undocumented - class_: str = ..., - command: Callable[[], Any] | str | list[str] | tuple[str, ...] = ..., - cursor: tkinter._Cursor = ..., - exportselection: bool = ..., # undocumented - font: _FontDescription = ..., # undocumented - foreground: tkinter._Color = ..., # undocumented - format: str = ..., - from_: float = ..., - increment: float = ..., - invalidcommand: tkinter._EntryValidateCommand = ..., # undocumented - justify: Literal["left", "center", "right"] = ..., # undocumented - name: str = ..., - show: Any = ..., # undocumented - state: str = ..., - style: str = ..., - takefocus: tkinter._TakeFocusValue = ..., - textvariable: tkinter.Variable = ..., # undocumented - to: float = ..., - validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ..., - validatecommand: tkinter._EntryValidateCommand = ..., - values: list[str] | tuple[str, ...] = ..., - width: int = ..., # undocumented - wrap: bool = ..., - xscrollcommand: tkinter._XYScrollCommand = ..., - ) -> None: ... - @overload # type: ignore[override] - def configure( - self, - cnf: dict[str, Any] | None = ..., - *, - background: tkinter._Color = ..., - command: Callable[[], Any] | str | list[str] | tuple[str, ...] = ..., - cursor: tkinter._Cursor = ..., - exportselection: bool = ..., - font: _FontDescription = ..., - foreground: tkinter._Color = ..., - format: str = ..., - from_: float = ..., - increment: float = ..., - invalidcommand: tkinter._EntryValidateCommand = ..., - justify: Literal["left", "center", "right"] = ..., - show: Any = ..., - state: str = ..., - style: str = ..., - takefocus: tkinter._TakeFocusValue = ..., - textvariable: tkinter.Variable = ..., - to: float = ..., - validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ..., - validatecommand: tkinter._EntryValidateCommand = ..., - values: list[str] | tuple[str, ...] = ..., - width: int = ..., - wrap: bool = ..., - xscrollcommand: tkinter._XYScrollCommand = ..., - ) -> dict[str, tuple[str, str, str, Any, Any]] | None: ... - @overload - def configure(self, cnf: str) -> tuple[str, str, str, Any, Any]: ... - config = configure # type: ignore[assignment] - def set(self, value: Any) -> None: ... +class Spinbox(Entry): + def __init__( + self, + master: tkinter.Misc | None = ..., + *, + background: tkinter._Color = ..., # undocumented + class_: str = ..., + command: Callable[[], Any] | str | list[str] | tuple[str, ...] = ..., + cursor: tkinter._Cursor = ..., + exportselection: bool = ..., # undocumented + font: _FontDescription = ..., # undocumented + foreground: tkinter._Color = ..., # undocumented + format: str = ..., + from_: float = ..., + increment: float = ..., + invalidcommand: tkinter._EntryValidateCommand = ..., # undocumented + justify: Literal["left", "center", "right"] = ..., # undocumented + name: str = ..., + show: Any = ..., # undocumented + state: str = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + textvariable: tkinter.Variable = ..., # undocumented + to: float = ..., + validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ..., + validatecommand: tkinter._EntryValidateCommand = ..., + values: list[str] | tuple[str, ...] = ..., + width: int = ..., # undocumented + wrap: bool = ..., + xscrollcommand: tkinter._XYScrollCommand = ..., + ) -> None: ... + @overload # type: ignore[override] + def configure( + self, + cnf: dict[str, Any] | None = ..., + *, + background: tkinter._Color = ..., + command: Callable[[], Any] | str | list[str] | tuple[str, ...] = ..., + cursor: tkinter._Cursor = ..., + exportselection: bool = ..., + font: _FontDescription = ..., + foreground: tkinter._Color = ..., + format: str = ..., + from_: float = ..., + increment: float = ..., + invalidcommand: tkinter._EntryValidateCommand = ..., + justify: Literal["left", "center", "right"] = ..., + show: Any = ..., + state: str = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + textvariable: tkinter.Variable = ..., + to: float = ..., + validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ..., + validatecommand: tkinter._EntryValidateCommand = ..., + values: list[str] | tuple[str, ...] = ..., + width: int = ..., + wrap: bool = ..., + xscrollcommand: tkinter._XYScrollCommand = ..., + ) -> dict[str, tuple[str, str, str, Any, Any]] | None: ... + @overload + def configure(self, cnf: str) -> tuple[str, str, str, Any, Any]: ... + config = configure # type: ignore[assignment] + def set(self, value: Any) -> None: ... class _TreeviewItemDict(TypedDict): text: str diff --git a/stdlib/token.pyi b/stdlib/token.pyi index 5fe9db7e230d..fcd6ef87d217 100644 --- a/stdlib/token.pyi +++ b/stdlib/token.pyi @@ -62,16 +62,13 @@ __all__ = [ "VBAR", "VBAREQUAL", "tok_name", + "ENCODING", + "NL", + "COMMENT", ] -if sys.version_info < (3, 7) or sys.version_info >= (3, 8): - __all__ += ["ASYNC", "AWAIT"] - -if sys.version_info >= (3, 7): - __all__ += ["ENCODING", "NL", "COMMENT"] - if sys.version_info >= (3, 8): - __all__ += ["COLONEQUAL", "TYPE_COMMENT", "TYPE_IGNORE"] + __all__ += ["ASYNC", "AWAIT", "COLONEQUAL", "TYPE_COMMENT", "TYPE_IGNORE"] if sys.version_info >= (3, 10): __all__ += ["SOFT_KEYWORD"] @@ -129,8 +126,7 @@ AT: int RARROW: int ELLIPSIS: int ATEQUAL: int -if sys.version_info < (3, 7) or sys.version_info >= (3, 8): - # These were removed in Python 3.7 but added back in Python 3.8 +if sys.version_info >= (3, 8): AWAIT: int ASYNC: int OP: int @@ -138,10 +134,9 @@ ERRORTOKEN: int N_TOKENS: int NT_OFFSET: int tok_name: dict[int, str] -if sys.version_info >= (3, 7): - COMMENT: int - NL: int - ENCODING: int +COMMENT: int +NL: int +ENCODING: int if sys.version_info >= (3, 8): TYPE_COMMENT: int TYPE_IGNORE: int diff --git a/stdlib/tokenize.pyi b/stdlib/tokenize.pyi index 3ac136150ab5..dddccc0a3879 100644 --- a/stdlib/tokenize.pyi +++ b/stdlib/tokenize.pyi @@ -77,11 +77,8 @@ __all__ = [ "untokenize", ] -if sys.version_info < (3, 7) or sys.version_info >= (3, 8): - __all__ += ["ASYNC", "AWAIT"] - if sys.version_info >= (3, 8): - __all__ += ["COLONEQUAL", "generate_tokens", "TYPE_COMMENT", "TYPE_IGNORE"] + __all__ += ["ASYNC", "AWAIT", "COLONEQUAL", "generate_tokens", "TYPE_COMMENT", "TYPE_IGNORE"] if sys.version_info >= (3, 10): __all__ += ["SOFT_KEYWORD"] @@ -91,11 +88,6 @@ if sys.version_info >= (3, 8): else: EXACT_TOKEN_TYPES: dict[str, int] -if sys.version_info < (3, 7): - COMMENT: int - NL: int - ENCODING: int - cookie_re: Pattern[str] blank_re: Pattern[bytes] @@ -167,10 +159,6 @@ Double3: str # undocumented Triple: str # undocumented String: str # undocumented -if sys.version_info < (3, 7): - Operator: str # undocumented - Bracket: str # undocumented - Special: str # undocumented Funny: str # undocumented diff --git a/stdlib/tracemalloc.pyi b/stdlib/tracemalloc.pyi index 4b7063e5d800..ed952616600f 100644 --- a/stdlib/tracemalloc.pyi +++ b/stdlib/tracemalloc.pyi @@ -83,11 +83,8 @@ class Traceback(Sequence[Frame]): def __init__(self, frames: Sequence[_FrameTuple], total_nframe: int | None = ...) -> None: ... else: def __init__(self, frames: Sequence[_FrameTuple]) -> None: ... - if sys.version_info >= (3, 7): - def format(self, limit: int | None = ..., most_recent_first: bool = ...) -> list[str]: ... - else: - def format(self, limit: int | None = ...) -> list[str]: ... + def format(self, limit: int | None = ..., most_recent_first: bool = ...) -> list[str]: ... @overload def __getitem__(self, index: SupportsIndex) -> Frame: ... @overload diff --git a/stdlib/types.pyi b/stdlib/types.pyi index ecd42dbe3ba3..1af4420e684d 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -41,17 +41,13 @@ __all__ = [ "DynamicClassAttribute", "coroutine", "BuiltinMethodType", + "ClassMethodDescriptorType", + "MethodDescriptorType", + "MethodWrapperType", + "WrapperDescriptorType", + "resolve_bases", ] -if sys.version_info >= (3, 7): - __all__ += [ - "ClassMethodDescriptorType", - "MethodDescriptorType", - "MethodWrapperType", - "WrapperDescriptorType", - "resolve_bases", - ] - if sys.version_info >= (3, 8): __all__ += ["CellType"] @@ -407,9 +403,8 @@ class CoroutineType(Coroutine[_T_co, _T_contra, _V_co]): def cr_frame(self) -> FrameType: ... @property def cr_running(self) -> bool: ... - if sys.version_info >= (3, 7): - @property - def cr_origin(self) -> tuple[tuple[str, int, str], ...] | None: ... + @property + def cr_origin(self) -> tuple[tuple[str, int, str], ...] | None: ... if sys.version_info >= (3, 11): @property def cr_suspended(self) -> bool: ... @@ -465,62 +460,57 @@ class BuiltinFunctionType: BuiltinMethodType = BuiltinFunctionType -if sys.version_info >= (3, 7): - @final - class WrapperDescriptorType: - @property - def __name__(self) -> str: ... - @property - def __qualname__(self) -> str: ... - @property - def __objclass__(self) -> type: ... - def __call__(self, *args: Any, **kwargs: Any) -> Any: ... - def __get__(self, __obj: Any, __type: type = ...) -> Any: ... +@final +class WrapperDescriptorType: + @property + def __name__(self) -> str: ... + @property + def __qualname__(self) -> str: ... + @property + def __objclass__(self) -> type: ... + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __get__(self, __obj: Any, __type: type = ...) -> Any: ... - @final - class MethodWrapperType: - @property - def __self__(self) -> object: ... - @property - def __name__(self) -> str: ... - @property - def __qualname__(self) -> str: ... - @property - def __objclass__(self) -> type: ... - def __call__(self, *args: Any, **kwargs: Any) -> Any: ... - def __eq__(self, __other: object) -> bool: ... - def __ne__(self, __other: object) -> bool: ... +@final +class MethodWrapperType: + @property + def __self__(self) -> object: ... + @property + def __name__(self) -> str: ... + @property + def __qualname__(self) -> str: ... + @property + def __objclass__(self) -> type: ... + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __eq__(self, __other: object) -> bool: ... + def __ne__(self, __other: object) -> bool: ... - @final - class MethodDescriptorType: - @property - def __name__(self) -> str: ... - @property - def __qualname__(self) -> str: ... - @property - def __objclass__(self) -> type: ... - def __call__(self, *args: Any, **kwargs: Any) -> Any: ... - def __get__(self, obj: Any, type: type = ...) -> Any: ... +@final +class MethodDescriptorType: + @property + def __name__(self) -> str: ... + @property + def __qualname__(self) -> str: ... + @property + def __objclass__(self) -> type: ... + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __get__(self, obj: Any, type: type = ...) -> Any: ... - @final - class ClassMethodDescriptorType: - @property - def __name__(self) -> str: ... - @property - def __qualname__(self) -> str: ... - @property - def __objclass__(self) -> type: ... - def __call__(self, *args: Any, **kwargs: Any) -> Any: ... - def __get__(self, obj: Any, type: type = ...) -> Any: ... +@final +class ClassMethodDescriptorType: + @property + def __name__(self) -> str: ... + @property + def __qualname__(self) -> str: ... + @property + def __objclass__(self) -> type: ... + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __get__(self, obj: Any, type: type = ...) -> Any: ... @final class TracebackType: - if sys.version_info >= (3, 7): - def __init__(self, tb_next: TracebackType | None, tb_frame: FrameType, tb_lasti: int, tb_lineno: int) -> None: ... - tb_next: TracebackType | None - else: - @property - def tb_next(self) -> TracebackType | None: ... + def __init__(self, tb_next: TracebackType | None, tb_frame: FrameType, tb_lasti: int, tb_lineno: int) -> None: ... + tb_next: TracebackType | None # the rest are read-only even in 3.7 @property def tb_frame(self) -> FrameType: ... @@ -549,9 +539,8 @@ class FrameType: @property def f_locals(self) -> dict[str, Any]: ... f_trace: Callable[[FrameType, str, Any], Any] | None - if sys.version_info >= (3, 7): - f_trace_lines: bool - f_trace_opcodes: bool + f_trace_lines: bool + f_trace_opcodes: bool def clear(self) -> None: ... @final @@ -578,23 +567,13 @@ class MemberDescriptorType: def __set__(self, __instance: Any, __value: Any) -> None: ... def __delete__(self, __obj: Any) -> None: ... -if sys.version_info >= (3, 7): - def new_class( - name: str, - bases: Iterable[object] = ..., - kwds: dict[str, Any] | None = ..., - exec_body: Callable[[dict[str, Any]], object] | None = ..., - ) -> type: ... - def resolve_bases(bases: Iterable[object]) -> tuple[Any, ...]: ... - -else: - def new_class( - name: str, - bases: tuple[type, ...] = ..., - kwds: dict[str, Any] | None = ..., - exec_body: Callable[[dict[str, Any]], object] | None = ..., - ) -> type: ... - +def new_class( + name: str, + bases: Iterable[object] = ..., + kwds: dict[str, Any] | None = ..., + exec_body: Callable[[dict[str, Any]], object] | None = ..., +) -> type: ... +def resolve_bases(bases: Iterable[object]) -> tuple[Any, ...]: ... def prepare_class( name: str, bases: tuple[type, ...] = ..., kwds: dict[str, Any] | None = ... ) -> tuple[type, dict[str, Any], dict[str, Any]]: ... diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index acbce5cd3a5f..41cd6b3eaf34 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -2,12 +2,20 @@ import collections # Needed by aliases like DefaultDict, see mypy issue 2986 import sys from _typeshed import IdentityFunction, ReadableBuffer, Self as TypeshedSelf, SupportsKeysAndGetItem from abc import ABCMeta, abstractmethod -from types import BuiltinFunctionType, CodeType, FrameType, FunctionType, MethodType, ModuleType, TracebackType +from types import ( + BuiltinFunctionType, + CodeType, + FrameType, + FunctionType, + MethodDescriptorType, + MethodType, + MethodWrapperType, + ModuleType, + TracebackType, + WrapperDescriptorType, +) from typing_extensions import Literal as _Literal, ParamSpec as _ParamSpec, final as _final -if sys.version_info >= (3, 7): - from types import MethodDescriptorType, MethodWrapperType, WrapperDescriptorType - if sys.version_info >= (3, 9): from types import GenericAlias @@ -71,14 +79,11 @@ __all__ = [ "no_type_check", "no_type_check_decorator", "overload", + "ForwardRef", + "NoReturn", + "OrderedDict", ] -if sys.version_info < (3, 7): - __all__ += ["GenericMeta"] - -if sys.version_info >= (3, 7): - __all__ += ["ForwardRef", "NoReturn", "OrderedDict"] - if sys.version_info >= (3, 8): __all__ += [ "Final", @@ -188,9 +193,6 @@ if sys.version_info >= (3, 11): def __init__(self, name: str) -> None: ... def __iter__(self) -> Any: ... -if sys.version_info < (3, 7): - class GenericMeta(type): ... - if sys.version_info >= (3, 10): class ParamSpecArgs: __origin__: ParamSpec @@ -255,8 +257,7 @@ Counter = _Alias() Deque = _Alias() ChainMap = _Alias() -if sys.version_info >= (3, 7): - OrderedDict = _Alias() +OrderedDict = _Alias() if sys.version_info >= (3, 9): Annotated: _SpecialForm @@ -824,22 +825,17 @@ class Pattern(Generic[AnyStr]): # Functions -if sys.version_info >= (3, 7): - _get_type_hints_obj_allowed_types = ( # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed - object - | Callable[..., Any] - | FunctionType - | BuiltinFunctionType - | MethodType - | ModuleType - | WrapperDescriptorType - | MethodWrapperType - | MethodDescriptorType - ) -else: - _get_type_hints_obj_allowed_types = ( # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed - object | Callable[..., Any] | FunctionType | BuiltinFunctionType | MethodType | ModuleType - ) +_get_type_hints_obj_allowed_types = ( # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed + object + | Callable[..., Any] + | FunctionType + | BuiltinFunctionType + | MethodType + | ModuleType + | WrapperDescriptorType + | MethodWrapperType + | MethodDescriptorType +) if sys.version_info >= (3, 9): def get_type_hints( @@ -919,28 +915,27 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta): def __or__(self: TypeshedSelf, __value: TypeshedSelf) -> TypeshedSelf: ... def __ior__(self: TypeshedSelf, __value: TypeshedSelf) -> TypeshedSelf: ... -if sys.version_info >= (3, 7): - @_final - class ForwardRef: - __forward_arg__: str - __forward_code__: CodeType - __forward_evaluated__: bool - __forward_value__: Any | None - __forward_is_argument__: bool - __forward_is_class__: bool - __forward_module__: Any | None - if sys.version_info >= (3, 9): - # The module and is_class arguments were added in later Python 3.9 versions. - def __init__(self, arg: str, is_argument: bool = ..., module: Any | None = ..., *, is_class: bool = ...) -> None: ... - else: - def __init__(self, arg: str, is_argument: bool = ...) -> None: ... - - def _evaluate(self, globalns: dict[str, Any] | None, localns: dict[str, Any] | None) -> Any | None: ... - def __eq__(self, other: object) -> bool: ... - def __hash__(self) -> int: ... - if sys.version_info >= (3, 11): - def __or__(self, other: Any) -> _SpecialForm: ... - def __ror__(self, other: Any) -> _SpecialForm: ... +@_final +class ForwardRef: + __forward_arg__: str + __forward_code__: CodeType + __forward_evaluated__: bool + __forward_value__: Any | None + __forward_is_argument__: bool + __forward_is_class__: bool + __forward_module__: Any | None + if sys.version_info >= (3, 9): + # The module and is_class arguments were added in later Python 3.9 versions. + def __init__(self, arg: str, is_argument: bool = ..., module: Any | None = ..., *, is_class: bool = ...) -> None: ... + else: + def __init__(self, arg: str, is_argument: bool = ...) -> None: ... + + def _evaluate(self, globalns: dict[str, Any] | None, localns: dict[str, Any] | None) -> Any | None: ... + def __eq__(self, other: object) -> bool: ... + def __hash__(self) -> int: ... + if sys.version_info >= (3, 11): + def __or__(self, other: Any) -> _SpecialForm: ... + def __ror__(self, other: Any) -> _SpecialForm: ... if sys.version_info >= (3, 10): def is_typeddict(tp: object) -> bool: ... diff --git a/stdlib/unittest/loader.pyi b/stdlib/unittest/loader.pyi index 76c60f4803f5..32e0bab4f577 100644 --- a/stdlib/unittest/loader.pyi +++ b/stdlib/unittest/loader.pyi @@ -1,4 +1,3 @@ -import sys import unittest.case import unittest.result import unittest.suite @@ -16,10 +15,7 @@ class TestLoader: errors: list[type[BaseException]] testMethodPrefix: str sortTestMethodsUsing: _SortComparisonMethod - - if sys.version_info >= (3, 7): - testNamePatterns: list[str] | None - + testNamePatterns: list[str] | None suiteClass: _SuiteClass def loadTestsFromTestCase(self, testCaseClass: type[unittest.case.TestCase]) -> unittest.suite.TestSuite: ... def loadTestsFromModule(self, module: ModuleType, *args: Any, pattern: Any = ...) -> unittest.suite.TestSuite: ... @@ -30,19 +26,12 @@ class TestLoader: defaultTestLoader: TestLoader -if sys.version_info >= (3, 7): - def getTestCaseNames( - testCaseClass: type[unittest.case.TestCase], - prefix: str, - sortUsing: _SortComparisonMethod = ..., - testNamePatterns: list[str] | None = ..., - ) -> Sequence[str]: ... - -else: - def getTestCaseNames( - testCaseClass: type[unittest.case.TestCase], prefix: str, sortUsing: _SortComparisonMethod = ... - ) -> Sequence[str]: ... - +def getTestCaseNames( + testCaseClass: type[unittest.case.TestCase], + prefix: str, + sortUsing: _SortComparisonMethod = ..., + testNamePatterns: list[str] | None = ..., +) -> Sequence[str]: ... def makeSuite( testCaseClass: type[unittest.case.TestCase], prefix: str = ..., diff --git a/stdlib/unittest/main.pyi b/stdlib/unittest/main.pyi index 31853676b011..915d559cce5b 100644 --- a/stdlib/unittest/main.pyi +++ b/stdlib/unittest/main.pyi @@ -1,4 +1,3 @@ -import sys import unittest.case import unittest.loader import unittest.result @@ -23,9 +22,7 @@ class TestProgram: buffer: bool | None progName: str | None warnings: str | None - - if sys.version_info >= (3, 7): - testNamePatterns: list[str] | None + testNamePatterns: list[str] | None def __init__( self, module: None | str | ModuleType = ..., @@ -44,11 +41,7 @@ class TestProgram: ) -> None: ... def usageExit(self, msg: Any = ...) -> None: ... def parseArgs(self, argv: list[str]) -> None: ... - if sys.version_info >= (3, 7): - def createTests(self, from_discovery: bool = ..., Loader: unittest.loader.TestLoader | None = ...) -> None: ... - else: - def createTests(self) -> None: ... - + def createTests(self, from_discovery: bool = ..., Loader: unittest.loader.TestLoader | None = ...) -> None: ... def runTests(self) -> None: ... # undocumented main = TestProgram diff --git a/stdlib/unittest/mock.pyi b/stdlib/unittest/mock.pyi index d4e9e832c929..4aa67f4995cd 100644 --- a/stdlib/unittest/mock.pyi +++ b/stdlib/unittest/mock.pyi @@ -28,23 +28,6 @@ if sys.version_info >= (3, 8): "PropertyMock", "seal", ) -elif sys.version_info >= (3, 7): - __all__ = ( - "Mock", - "MagicMock", - "patch", - "sentinel", - "DEFAULT", - "ANY", - "call", - "create_autospec", - "FILTER_DIR", - "NonCallableMock", - "NonCallableMagicMock", - "mock_open", - "PropertyMock", - "seal", - ) else: __all__ = ( "Mock", @@ -60,7 +43,9 @@ else: "NonCallableMagicMock", "mock_open", "PropertyMock", + "seal", ) + __version__: str FILTER_DIR: Any @@ -155,10 +140,8 @@ class NonCallableMock(Base, Any): def assert_called_once(_mock_self) -> None: ... def reset_mock(self, visited: Any = ..., *, return_value: bool = ..., side_effect: bool = ...) -> None: ... - if sys.version_info >= (3, 7): - def _extract_mock_name(self) -> str: ... - def _get_call_signature_from_name(self, name: str) -> Any: ... - + def _extract_mock_name(self) -> str: ... + def _get_call_signature_from_name(self, name: str) -> Any: ... def assert_any_call(self, *args: Any, **kwargs: Any) -> None: ... def assert_has_calls(self, calls: Sequence[_Call], any_order: bool = ...) -> None: ... def mock_add_spec(self, spec: Any, spec_set: bool = ...) -> None: ... @@ -446,5 +429,4 @@ class PropertyMock(Mock): def __set__(self, obj: Any, value: Any) -> None: ... -if sys.version_info >= (3, 7): - def seal(mock: Any) -> None: ... +def seal(mock: Any) -> None: ... diff --git a/stdlib/uu.pyi b/stdlib/uu.pyi index 4ebb12be8858..95a7f3dfa9e2 100644 --- a/stdlib/uu.pyi +++ b/stdlib/uu.pyi @@ -1,4 +1,3 @@ -import sys from typing import BinaryIO from typing_extensions import TypeAlias @@ -8,12 +7,5 @@ _File: TypeAlias = str | BinaryIO class Error(Exception): ... -if sys.version_info >= (3, 7): - def encode( - in_file: _File, out_file: _File, name: str | None = ..., mode: int | None = ..., *, backtick: bool = ... - ) -> None: ... - -else: - def encode(in_file: _File, out_file: _File, name: str | None = ..., mode: int | None = ...) -> None: ... - +def encode(in_file: _File, out_file: _File, name: str | None = ..., mode: int | None = ..., *, backtick: bool = ...) -> None: ... def decode(in_file: _File, out_file: _File | None = ..., mode: int | None = ..., quiet: int = ...) -> None: ... diff --git a/stdlib/uuid.pyi b/stdlib/uuid.pyi index fd7f1334e52a..3d9b89a0b9f7 100644 --- a/stdlib/uuid.pyi +++ b/stdlib/uuid.pyi @@ -1,4 +1,4 @@ -import sys +from enum import Enum from typing_extensions import TypeAlias # Because UUID has properties called int and bytes we need to rename these temporarily. @@ -6,40 +6,25 @@ _Int: TypeAlias = int _Bytes: TypeAlias = bytes _FieldsType: TypeAlias = tuple[int, int, int, int, int, int] -if sys.version_info >= (3, 7): - from enum import Enum - - class SafeUUID(Enum): - safe: int - unsafe: int - unknown: None +class SafeUUID(Enum): + safe: int + unsafe: int + unknown: None class UUID: - if sys.version_info >= (3, 7): - def __init__( - self, - hex: str | None = ..., - bytes: _Bytes | None = ..., - bytes_le: _Bytes | None = ..., - fields: _FieldsType | None = ..., - int: _Int | None = ..., - version: _Int | None = ..., - *, - is_safe: SafeUUID = ..., - ) -> None: ... - @property - def is_safe(self) -> SafeUUID: ... - else: - def __init__( - self, - hex: str | None = ..., - bytes: _Bytes | None = ..., - bytes_le: _Bytes | None = ..., - fields: _FieldsType | None = ..., - int: _Int | None = ..., - version: _Int | None = ..., - ) -> None: ... - + def __init__( + self, + hex: str | None = ..., + bytes: _Bytes | None = ..., + bytes_le: _Bytes | None = ..., + fields: _FieldsType | None = ..., + int: _Int | None = ..., + version: _Int | None = ..., + *, + is_safe: SafeUUID = ..., + ) -> None: ... + @property + def is_safe(self) -> SafeUUID: ... @property def bytes(self) -> _Bytes: ... @property diff --git a/stdlib/webbrowser.pyi b/stdlib/webbrowser.pyi index a5b04a262596..8cf8935ffaad 100644 --- a/stdlib/webbrowser.pyi +++ b/stdlib/webbrowser.pyi @@ -7,16 +7,9 @@ __all__ = ["Error", "open", "open_new", "open_new_tab", "get", "register"] class Error(Exception): ... -if sys.version_info >= (3, 7): - def register( - name: str, klass: Callable[[], BaseBrowser] | None, instance: BaseBrowser | None = ..., *, preferred: bool = ... - ) -> None: ... - -else: - def register( - name: str, klass: Callable[[], BaseBrowser] | None, instance: BaseBrowser | None = ..., update_tryorder: int = ... - ) -> None: ... - +def register( + name: str, klass: Callable[[], BaseBrowser] | None, instance: BaseBrowser | None = ..., *, preferred: bool = ... +) -> None: ... def get(using: str | None = ...) -> BaseBrowser: ... def open(url: str, new: int = ..., autoraise: bool = ...) -> bool: ... def open_new(url: str) -> bool: ... diff --git a/stdlib/xmlrpc/server.pyi b/stdlib/xmlrpc/server.pyi index 237620f70250..cb1a130ac6f2 100644 --- a/stdlib/xmlrpc/server.pyi +++ b/stdlib/xmlrpc/server.pyi @@ -1,7 +1,6 @@ import http.server import pydoc import socketserver -import sys from collections.abc import Callable, Iterable, Mapping from datetime import datetime from typing import Any, ClassVar, Pattern, Protocol @@ -48,11 +47,7 @@ class SimpleXMLRPCDispatcher: # undocumented use_builtin_types: bool def __init__(self, allow_none: bool = ..., encoding: str | None = ..., use_builtin_types: bool = ...) -> None: ... def register_instance(self, instance: Any, allow_dotted_names: bool = ...) -> None: ... - if sys.version_info >= (3, 7): - def register_function(self, function: _DispatchProtocol | None = ..., name: str | None = ...) -> Callable[..., Any]: ... - else: - def register_function(self, function: _DispatchProtocol, name: str | None = ...) -> Callable[..., Any]: ... - + def register_function(self, function: _DispatchProtocol | None = ..., name: str | None = ...) -> Callable[..., Any]: ... def register_introspection_functions(self) -> None: ... def register_multicall_functions(self) -> None: ... def _marshaled_dispatch( diff --git a/stdlib/zipapp.pyi b/stdlib/zipapp.pyi index d42640141620..3363161c3c6f 100644 --- a/stdlib/zipapp.pyi +++ b/stdlib/zipapp.pyi @@ -1,4 +1,3 @@ -import sys from collections.abc import Callable from pathlib import Path from typing import BinaryIO @@ -10,19 +9,12 @@ _Path: TypeAlias = str | Path | BinaryIO class ZipAppError(ValueError): ... -if sys.version_info >= (3, 7): - def create_archive( - source: _Path, - target: _Path | None = ..., - interpreter: str | None = ..., - main: str | None = ..., - filter: Callable[[Path], bool] | None = ..., - compressed: bool = ..., - ) -> None: ... - -else: - def create_archive( - source: _Path, target: _Path | None = ..., interpreter: str | None = ..., main: str | None = ... - ) -> None: ... - +def create_archive( + source: _Path, + target: _Path | None = ..., + interpreter: str | None = ..., + main: str | None = ..., + filter: Callable[[Path], bool] | None = ..., + compressed: bool = ..., +) -> None: ... def get_interpreter(archive: _Path) -> str: ... diff --git a/stdlib/zipfile.pyi b/stdlib/zipfile.pyi index c799cf9b4e12..da1710787252 100644 --- a/stdlib/zipfile.pyi +++ b/stdlib/zipfile.pyi @@ -1,7 +1,7 @@ import io import sys from _typeshed import Self, StrOrBytesPath, StrPath -from collections.abc import Callable, Iterable, Iterator, Sequence +from collections.abc import Callable, Iterable, Iterator from os import PathLike from types import TracebackType from typing import IO, Any, Protocol, overload @@ -56,78 +56,38 @@ class _ClosableZipStream(_ZipStream, Protocol): class ZipExtFile(io.BufferedIOBase): MAX_N: int MIN_READ_SIZE: int - - if sys.version_info >= (3, 7): - MAX_SEEK_READ: int - + MAX_SEEK_READ: int newlines: list[bytes] | None mode: _ReadWriteMode name: str - if sys.version_info >= (3, 7): - @overload - def __init__( - self, - fileobj: _ClosableZipStream, - mode: _ReadWriteMode, - zipinfo: ZipInfo, - pwd: bytes | None, - close_fileobj: Literal[True], - ) -> None: ... - @overload - def __init__( - self, - fileobj: _ClosableZipStream, - mode: _ReadWriteMode, - zipinfo: ZipInfo, - pwd: bytes | None = ..., - *, - close_fileobj: Literal[True], - ) -> None: ... - @overload - def __init__( - self, - fileobj: _ZipStream, - mode: _ReadWriteMode, - zipinfo: ZipInfo, - pwd: bytes | None = ..., - close_fileobj: Literal[False] = ..., - ) -> None: ... - else: - @overload - def __init__( - self, - fileobj: _ClosableZipStream, - mode: _ReadWriteMode, - zipinfo: ZipInfo, - decrypter: Callable[[Sequence[int]], bytes] | None, - close_fileobj: Literal[True], - ) -> None: ... - @overload - def __init__( - self, - fileobj: _ClosableZipStream, - mode: _ReadWriteMode, - zipinfo: ZipInfo, - decrypter: Callable[[Sequence[int]], bytes] | None = ..., - *, - close_fileobj: Literal[True], - ) -> None: ... - @overload - def __init__( - self, - fileobj: _ZipStream, - mode: _ReadWriteMode, - zipinfo: ZipInfo, - decrypter: Callable[[Sequence[int]], bytes] | None = ..., - close_fileobj: Literal[False] = ..., - ) -> None: ... - + @overload + def __init__( + self, fileobj: _ClosableZipStream, mode: _ReadWriteMode, zipinfo: ZipInfo, pwd: bytes | None, close_fileobj: Literal[True] + ) -> None: ... + @overload + def __init__( + self, + fileobj: _ClosableZipStream, + mode: _ReadWriteMode, + zipinfo: ZipInfo, + pwd: bytes | None = ..., + *, + close_fileobj: Literal[True], + ) -> None: ... + @overload + def __init__( + self, + fileobj: _ZipStream, + mode: _ReadWriteMode, + zipinfo: ZipInfo, + pwd: bytes | None = ..., + close_fileobj: Literal[False] = ..., + ) -> None: ... def read(self, n: int | None = ...) -> bytes: ... def readline(self, limit: int = ...) -> bytes: ... # type: ignore[override] def peek(self, n: int = ...) -> bytes: ... def read1(self, n: int | None) -> bytes: ... # type: ignore[override] - if sys.version_info >= (3, 7): - def seek(self, offset: int, whence: int = ...) -> int: ... + def seek(self, offset: int, whence: int = ...) -> int: ... class _Writer(Protocol): def write(self, __s: str) -> object: ... @@ -180,7 +140,7 @@ class ZipFile: *, strict_timestamps: bool = ..., ) -> None: ... - elif sys.version_info >= (3, 7): + else: def __init__( self, file: StrPath | IO[bytes], @@ -189,10 +149,6 @@ class ZipFile: allowZip64: bool = ..., compresslevel: int | None = ..., ) -> None: ... - else: - def __init__( - self, file: StrPath | IO[bytes], mode: _ZipFileMode = ..., compression: int = ..., allowZip64: bool = ... - ) -> None: ... def __enter__(self: Self) -> Self: ... def __exit__( @@ -213,26 +169,12 @@ class ZipFile: def setpassword(self, pwd: bytes) -> None: ... def read(self, name: str | ZipInfo, pwd: bytes | None = ...) -> bytes: ... def testzip(self) -> str | None: ... - if sys.version_info >= (3, 7): - def write( - self, - filename: StrPath, - arcname: StrPath | None = ..., - compress_type: int | None = ..., - compresslevel: int | None = ..., - ) -> None: ... - else: - def write(self, filename: StrPath, arcname: StrPath | None = ..., compress_type: int | None = ...) -> None: ... - if sys.version_info >= (3, 7): - def writestr( - self, - zinfo_or_arcname: str | ZipInfo, - data: bytes | str, - compress_type: int | None = ..., - compresslevel: int | None = ..., - ) -> None: ... - else: - def writestr(self, zinfo_or_arcname: str | ZipInfo, data: bytes | str, compress_type: int | None = ...) -> None: ... + def write( + self, filename: StrPath, arcname: StrPath | None = ..., compress_type: int | None = ..., compresslevel: int | None = ... + ) -> None: ... + def writestr( + self, zinfo_or_arcname: str | ZipInfo, data: bytes | str, compress_type: int | None = ..., compresslevel: int | None = ... + ) -> None: ... if sys.version_info >= (3, 11): def mkdir(self, zinfo_or_directory_name: str | ZipInfo, mode: int = ...) -> None: ... diff --git a/stdlib/zipimport.pyi b/stdlib/zipimport.pyi index a0e6d9e258dc..db06544138ca 100644 --- a/stdlib/zipimport.pyi +++ b/stdlib/zipimport.pyi @@ -1,12 +1,10 @@ import os import sys +from importlib.abc import ResourceReader from importlib.machinery import ModuleSpec from types import CodeType, ModuleType from typing import Any -if sys.version_info >= (3, 7): - from importlib.abc import ResourceReader - if sys.version_info >= (3, 8): __all__ = ["ZipImportError", "zipimporter"] @@ -21,9 +19,7 @@ class zipimporter: def get_code(self, fullname: str) -> CodeType: ... def get_data(self, pathname: str) -> str: ... def get_filename(self, fullname: str) -> str: ... - if sys.version_info >= (3, 7): - def get_resource_reader(self, fullname: str) -> ResourceReader | None: ... # undocumented - + def get_resource_reader(self, fullname: str) -> ResourceReader | None: ... # undocumented def get_source(self, fullname: str) -> str | None: ... def is_package(self, fullname: str) -> bool: ... def load_module(self, fullname: str) -> ModuleType: ... diff --git a/stubs/SQLAlchemy/sqlalchemy/util/_collections.pyi b/stubs/SQLAlchemy/sqlalchemy/util/_collections.pyi index 153b6952e758..47e97b30418e 100644 --- a/stubs/SQLAlchemy/sqlalchemy/util/_collections.pyi +++ b/stubs/SQLAlchemy/sqlalchemy/util/_collections.pyi @@ -1,5 +1,4 @@ import collections.abc -import sys from _typeshed import Self, SupportsKeysAndGetItem from collections.abc import Callable, Iterable, Iterator, Mapping from typing import Any, Generic, NoReturn, TypeVar, overload @@ -68,25 +67,7 @@ class OrderedProperties(Properties[_T], Generic[_T]): class ImmutableProperties(ImmutableContainer, Properties[_T], Generic[_T]): ... -if sys.version_info >= (3, 7): - OrderedDict = dict -else: - class OrderedDict(dict[Any, Any]): - def __reduce__(self): ... - def __init__(self, ____sequence: Any | None = ..., **kwargs) -> None: ... - def clear(self) -> None: ... - def copy(self): ... - def __copy__(self): ... - def update(self, ____sequence: Any | None = ..., **kwargs) -> None: ... - def setdefault(self, key, value): ... - def __iter__(self): ... - def keys(self): ... - def values(self): ... - def items(self): ... - def __setitem__(self, key, obj) -> None: ... - def __delitem__(self, key) -> None: ... - def pop(self, key, *default): ... - def popitem(self): ... +OrderedDict = dict def sort_dictionary(d, key: Any | None = ...): ... diff --git a/stubs/html5lib/html5lib/_tokenizer.pyi b/stubs/html5lib/html5lib/_tokenizer.pyi index 6c7d0b41e26d..158218c6f4fc 100644 --- a/stubs/html5lib/html5lib/_tokenizer.pyi +++ b/stubs/html5lib/html5lib/_tokenizer.pyi @@ -1,13 +1,8 @@ -import sys -from collections import OrderedDict from typing import Any from typing_extensions import TypeAlias entitiesTrie: Any -if sys.version_info >= (3, 7): - attributeMap: TypeAlias = dict[Any, Any] -else: - attributeMap: TypeAlias = OrderedDict[Any, Any] +attributeMap: TypeAlias = dict[Any, Any] class HTMLTokenizer: stream: Any diff --git a/stubs/setuptools/setuptools/command/py36compat.pyi b/stubs/setuptools/setuptools/command/py36compat.pyi index 2143abc0577b..eac937030d12 100644 --- a/stubs/setuptools/setuptools/command/py36compat.pyi +++ b/stubs/setuptools/setuptools/command/py36compat.pyi @@ -1,5 +1 @@ -import sys - -class sdist_add_defaults: - if sys.version_info < (3, 7): - def add_defaults(self) -> None: ... +class sdist_add_defaults: ...