stdlib: Improve a bunch of __(a)exit__ methods (#7571)

This commit is contained in:
Alex Waygood
2022-04-01 07:05:25 +01:00
committed by GitHub
parent 85f060b26d
commit da3e69d093
20 changed files with 47 additions and 28 deletions

View File

@@ -1,3 +1,4 @@
from types import TracebackType
from typing import Any, Callable, NoReturn
TIMEOUT_MAX: int
@@ -14,7 +15,7 @@ class LockType:
def __init__(self) -> None: ...
def acquire(self, waitflag: bool | None = ..., timeout: int = ...) -> bool: ...
def __enter__(self, waitflag: bool | None = ..., timeout: int = ...) -> bool: ...
def __exit__(self, typ: Any, val: Any, tb: Any) -> None: ...
def __exit__(self, typ: type[BaseException] | None, val: BaseException | None, tb: TracebackType | None) -> None: ...
def release(self) -> bool: ...
def locked(self) -> bool: ...

View File

@@ -123,7 +123,7 @@ class AbstractServer:
def close(self) -> None: ...
if sys.version_info >= (3, 7):
async def __aenter__(self: Self) -> Self: ...
async def __aexit__(self, *exc: Any) -> None: ...
async def __aexit__(self, *exc: object) -> None: ...
@abstractmethod
def get_loop(self) -> AbstractEventLoop: ...
@abstractmethod

View File

@@ -25,7 +25,7 @@ else:
class _ContextManager:
def __init__(self, lock: Lock | Semaphore) -> None: ...
def __enter__(self) -> None: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...
class _ContextManagerMixin:
# Apparently this exists to *prohibit* use as a context manager.

View File

@@ -31,7 +31,7 @@ if sys.platform == "win32":
def __del__(self) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, t: type | None, v: BaseException | None, tb: TracebackType | None) -> None: ...
def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ...
@property
def handle(self) -> int: ...
def fileno(self) -> int: ...

View File

@@ -31,6 +31,6 @@ class Profile:
def runcall(self, __func: Callable[_P, _T], *args: _P.args, **kw: _P.kwargs) -> _T: ...
if sys.version_info >= (3, 8):
def __enter__(self: Self) -> Self: ...
def __exit__(self, *exc_info: Any) -> None: ...
def __exit__(self, *exc_info: object) -> None: ...
def label(code: str | CodeType) -> _Label: ... # undocumented

View File

@@ -1,7 +1,7 @@
import datetime
import sys
from collections.abc import Iterable, Sequence
from time import struct_time
from typing import Any, Iterable, Sequence
from typing_extensions import Literal
__all__ = [
@@ -106,7 +106,7 @@ class HTMLCalendar(Calendar):
class different_locale:
def __init__(self, locale: _LocaleType) -> None: ...
def __enter__(self) -> None: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...
class LocaleTextCalendar(TextCalendar):
def __init__(self, firstweekday: int = ..., locale: _LocaleType | None = ...) -> None: ...

View File

@@ -127,7 +127,7 @@ class FieldStorage:
separator: str = ...,
) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...
def __iter__(self) -> Iterator[str]: ...
def __getitem__(self, key: str) -> Any: ...
def getvalue(self, key: str, default: Any = ...) -> Any: ...

View File

@@ -4,6 +4,7 @@ from _typeshed import Self
from abc import abstractmethod
from collections.abc import Container, Iterable, Iterator, Sequence
from logging import Logger
from types import TracebackType
from typing import Any, Callable, Generic, Protocol, TypeVar, overload
from typing_extensions import Literal, ParamSpec, SupportsIndex
@@ -73,7 +74,9 @@ class Executor:
def shutdown(self, wait: bool = ...) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool | None: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> bool | None: ...
def as_completed(fs: Iterable[Future[_T]], timeout: float | None = ...) -> Iterator[Future[_T]]: ...
@@ -127,4 +130,4 @@ class _AcquireFutures:
futures: Iterable[Future[Any]]
def __init__(self, futures: Iterable[Future[Any]]) -> None: ...
def __enter__(self) -> None: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...

View File

@@ -217,9 +217,9 @@ if sys.version_info >= (3, 10):
@overload
def __init__(self: nullcontext[_T], enter_result: _T) -> None: ...
def __enter__(self) -> _T: ...
def __exit__(self, *exctype: Any) -> None: ...
def __exit__(self, *exctype: object) -> None: ...
async def __aenter__(self) -> _T: ...
async def __aexit__(self, *exctype: Any) -> None: ...
async def __aexit__(self, *exctype: object) -> None: ...
elif sys.version_info >= (3, 7):
class nullcontext(AbstractContextManager[_T]):
@@ -229,7 +229,7 @@ elif sys.version_info >= (3, 7):
@overload
def __init__(self: nullcontext[_T], enter_result: _T) -> None: ...
def __enter__(self) -> _T: ...
def __exit__(self, *exctype: Any) -> None: ...
def __exit__(self, *exctype: object) -> None: ...
if sys.version_info >= (3, 11):
_T_fd_or_any_path = TypeVar("_T_fd_or_any_path", bound=int | StrOrBytesPath)

View File

@@ -1,5 +1,6 @@
import sys
from _typeshed import Self, StrOrBytesPath
from types import TracebackType
from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Iterator
__all__ = [
@@ -98,7 +99,9 @@ class FileInput(Iterator[AnyStr], Generic[AnyStr]):
def __del__(self) -> None: ...
def close(self) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ...
def __exit__(
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
) -> None: ...
def __iter__(self: Self) -> Self: ...
def __next__(self) -> AnyStr: ...
if sys.version_info < (3, 11):

View File

@@ -3,6 +3,7 @@ from collections.abc import Callable, Iterable, Sequence
from ctypes import _CData, _SimpleCData, c_char
from multiprocessing.context import BaseContext
from multiprocessing.synchronize import _LockLike
from types import TracebackType
from typing import Any, Generic, Protocol, TypeVar, overload
from typing_extensions import Literal
@@ -82,7 +83,9 @@ class SynchronizedBase(Generic[_CT]):
def get_obj(self) -> _CT: ...
def get_lock(self) -> _LockLike: ...
def __enter__(self) -> bool: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(
self, __exc_type: type[BaseException] | None, __exc_val: BaseException | None, __exc_tb: TracebackType | None
) -> None: ...
class Synchronized(SynchronizedBase[_SimpleCData[_T]], Generic[_T]):
value: _T

View File

@@ -73,7 +73,7 @@ class NNTP:
timeout: float = ...,
) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...
def getwelcome(self) -> str: ...
def getcapabilities(self) -> dict[str, _list[str]]: ...
def set_debuglevel(self, level: int) -> None: ...

View File

@@ -1021,7 +1021,7 @@ if sys.version_info >= (3, 8):
def __init__(self, path: str | None, cookie: _T, remove_dll_directory: Callable[[_T], Any]) -> None: ...
def close(self) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...
def add_dll_directory(path: str) -> _AddedDllDirectory: ...
if sys.platform == "linux":

View File

@@ -9,13 +9,13 @@ class _TempModule:
module: ModuleType
def __init__(self, mod_name: str) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...
class _ModifiedArgv0:
value: Any
def __init__(self, value: Any) -> None: ...
def __enter__(self) -> None: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...
def run_module(
mod_name: str, init_globals: dict[str, Any] | None = ..., run_name: str | None = ..., alter_sys: bool = ...

View File

@@ -27,7 +27,7 @@ class BaseSelector(metaclass=ABCMeta):
@abstractmethod
def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...
class SelectSelector(BaseSelector):
def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = ...) -> SelectorKey: ...

View File

@@ -1,6 +1,7 @@
import sys
from _typeshed import Self, StrOrBytesPath
from datetime import date, datetime, time
from types import TracebackType
from typing import Any, Callable, Generator, Iterable, Iterator, Protocol, TypeVar
from typing_extensions import Literal, final
@@ -183,7 +184,9 @@ class Connection:
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, __type: type | None, __value: BaseException | None, __traceback: Any | None) -> Literal[False]: ...
def __exit__(
self, __type: type[BaseException] | None, __value: BaseException | None, __traceback: TracebackType | None
) -> Literal[False]: ...
class Cursor(Iterator[Any]):
arraysize: Any

View File

@@ -33,7 +33,7 @@ class _sunau_params(NamedTuple):
class Au_read:
def __init__(self, f: _File) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...
def getfp(self) -> IO[bytes] | None: ...
def rewind(self) -> None: ...
def close(self) -> None: ...
@@ -53,7 +53,7 @@ class Au_read:
class Au_write:
def __init__(self, f: _File) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...
def setnchannels(self, nchannels: int) -> None: ...
def getnchannels(self) -> int: ...
def setsampwidth(self, sampwidth: int) -> None: ...

View File

@@ -1,5 +1,6 @@
import socket
from _typeshed import Self
from types import TracebackType
from typing import Any, Callable, Match, Pattern, Sequence
__all__ = ["Telnet"]
@@ -113,4 +114,6 @@ class Telnet:
self, list: Sequence[Pattern[bytes] | bytes], timeout: float | None = ...
) -> tuple[int, Match[bytes] | None, bytes]: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ...
def __exit__(
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
) -> None: ...

View File

@@ -1,6 +1,7 @@
import sys
from _typeshed import Self
from contextlib import _GeneratorContextManager
from types import TracebackType
from typing import Any, Awaitable, Callable, Generic, Iterable, Mapping, Sequence, TypeVar, overload
from typing_extensions import Literal
@@ -263,7 +264,9 @@ class _patch(Generic[_T]):
temp_original: Any
is_local: bool
def __enter__(self) -> _T: ...
def __exit__(self, *exc_info: Any) -> None: ...
def __exit__(
self, __exc_type: type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
) -> None: ...
def start(self) -> _T: ...
def stop(self) -> None: ...
@@ -275,7 +278,7 @@ class _patch_dict:
def __call__(self, f: Any) -> Any: ...
def decorate_class(self, klass: Any) -> Any: ...
def __enter__(self) -> Any: ...
def __exit__(self, *args: Any) -> Any: ...
def __exit__(self, *args: object) -> Any: ...
start: Any
stop: Any

View File

@@ -25,7 +25,7 @@ class _wave_params(NamedTuple):
class Wave_read:
def __init__(self, f: _File) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...
def getfp(self) -> BinaryIO | None: ...
def rewind(self) -> None: ...
def close(self) -> None: ...
@@ -45,7 +45,7 @@ class Wave_read:
class Wave_write:
def __init__(self, f: _File) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...
def setnchannels(self, nchannels: int) -> None: ...
def getnchannels(self) -> int: ...
def setsampwidth(self, sampwidth: int) -> None: ...