Third-party stubs: Improve several __exit__ methods (#7575)

This commit is contained in:
Alex Waygood
2022-04-01 16:03:12 +01:00
committed by GitHub
parent 4c9dc43c87
commit ec27c00ca2
12 changed files with 49 additions and 21 deletions

View File

@@ -119,7 +119,7 @@ class Image:
@property
def size(self) -> tuple[int, int]: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...
def close(self) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __array__(self, dtype=...) -> Any: ... # returns numpy.array()

View File

@@ -41,7 +41,7 @@ class Parser:
decode: Any
def feed(self, data) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...
def close(self) -> Image: ...
class PyCodecState:

View File

@@ -24,7 +24,7 @@ class Cursor:
def callproc(self, procname: Text, args: Iterable[Any] = ...) -> Any: ...
def scroll(self, value: int, mode: Text = ...) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *exc_info: Any) -> None: ...
def __exit__(self, *exc_info: object) -> None: ...
# Methods returning result tuples are below.
def fetchone(self) -> tuple[Any, ...] | None: ...
def fetchmany(self, size: int | None = ...) -> tuple[tuple[Any, ...], ...]: ...

View File

@@ -1,5 +1,6 @@
import sys
from _typeshed import SupportsWrite
from types import TracebackType
from typing import Any, Callable, Pattern, Sequence, TextIO, Union
if sys.platform == "win32":
@@ -13,7 +14,9 @@ class StreamWrapper:
def __init__(self, wrapped: TextIO, converter: SupportsWrite[str]) -> None: ...
def __getattr__(self, name: str) -> Any: ...
def __enter__(self, *args: object, **kwargs: object) -> TextIO: ...
def __exit__(self, *args: Any, **kwargs: Any) -> None: ...
def __exit__(
self, __t: type[BaseException] | None, __value: BaseException | None, __traceback: TracebackType | None, **kwargs: Any
) -> None: ...
def write(self, text: str) -> None: ...
def isatty(self) -> bool: ...
@property

View File

@@ -41,7 +41,7 @@ class _freeze_time:
@overload
def __call__(self, func: Callable[..., _T]) -> Callable[..., _T]: ...
def __enter__(self) -> FrozenDateTimeFactory | StepTickTimeFactory: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...
def start(self) -> Any: ...
def stop(self) -> None: ...
def decorate_class(self, klass: type[_T]) -> _T: ...

View File

@@ -1,4 +1,5 @@
import datetime
from types import TracebackType
from typing import Any, NamedTuple, Pattern
class SizeUnit(NamedTuple):
@@ -36,7 +37,12 @@ class Timer:
total_time: float
def __init__(self, start_time: Any | None = ..., resumable: bool = ...) -> None: ...
def __enter__(self): ...
def __exit__(self, exc_type: Any | None = ..., exc_value: Any | None = ..., traceback: Any | None = ...) -> None: ...
def __exit__(
self,
exc_type: type[BaseException] | None = ...,
exc_value: BaseException | None = ...,
traceback: TracebackType | None = ...,
) -> None: ...
def sleep(self, seconds: float) -> None: ...
@property
def elapsed_time(self): ...

View File

@@ -1,3 +1,4 @@
from types import TracebackType
from typing import Any
GLYPHS: Any
@@ -18,7 +19,12 @@ class Spinner:
def sleep(self) -> None: ...
def clear(self) -> None: ...
def __enter__(self): ...
def __exit__(self, exc_type: Any | None = ..., exc_value: Any | None = ..., traceback: Any | None = ...) -> None: ...
def __exit__(
self,
exc_type: type[BaseException] | None = ...,
exc_value: BaseException | None = ...,
traceback: TracebackType | None = ...,
) -> None: ...
class AutomaticSpinner:
label: Any
@@ -27,4 +33,9 @@ class AutomaticSpinner:
subprocess: Any
def __init__(self, label, show_time: bool = ...) -> None: ...
def __enter__(self) -> None: ...
def __exit__(self, exc_type: Any | None = ..., exc_value: Any | None = ..., traceback: Any | None = ...) -> None: ...
def __exit__(
self,
exc_type: type[BaseException] | None = ...,
exc_value: BaseException | None = ...,
traceback: TracebackType | None = ...,
) -> None: ...

View File

@@ -1,4 +1,5 @@
import unittest
from types import TracebackType
from typing import Any
from humanfriendly.compat import StringIO
@@ -14,7 +15,12 @@ class CallableTimedOut(Exception): ...
class ContextManager:
def __enter__(self): ...
def __exit__(self, exc_type: Any | None = ..., exc_value: Any | None = ..., traceback: Any | None = ...) -> None: ...
def __exit__(
self,
exc_type: type[BaseException] | None = ...,
exc_value: BaseException | None = ...,
traceback: TracebackType | None = ...,
) -> None: ...
class PatchedAttribute(ContextManager):
object_to_patch: Any
@@ -23,7 +29,6 @@ class PatchedAttribute(ContextManager):
original_value: Any
def __init__(self, obj, name, value) -> None: ...
def __enter__(self): ...
def __exit__(self, exc_type: Any | None = ..., exc_value: Any | None = ..., traceback: Any | None = ...) -> None: ...
class PatchedItem(ContextManager):
object_to_patch: Any
@@ -32,27 +37,23 @@ class PatchedItem(ContextManager):
original_value: Any
def __init__(self, obj, item, value) -> None: ...
def __enter__(self): ...
def __exit__(self, exc_type: Any | None = ..., exc_value: Any | None = ..., traceback: Any | None = ...) -> None: ...
class TemporaryDirectory(ContextManager):
mkdtemp_options: Any
temporary_directory: Any
def __init__(self, **options) -> None: ...
def __enter__(self): ...
def __exit__(self, exc_type: Any | None = ..., exc_value: Any | None = ..., traceback: Any | None = ...) -> None: ...
class MockedHomeDirectory(PatchedItem, TemporaryDirectory):
def __init__(self) -> None: ...
patched_value: Any
def __enter__(self): ...
def __exit__(self, exc_type: Any | None = ..., exc_value: Any | None = ..., traceback: Any | None = ...) -> None: ...
class CustomSearchPath(PatchedItem, TemporaryDirectory):
isolated_search_path: Any
def __init__(self, isolated: bool = ...) -> None: ...
patched_value: Any
def __enter__(self): ...
def __exit__(self, exc_type: Any | None = ..., exc_value: Any | None = ..., traceback: Any | None = ...) -> None: ...
@property
def current_search_path(self): ...
@@ -72,7 +73,6 @@ class CaptureOutput(ContextManager):
patched_attributes: Any
def __init__(self, merged: bool = ..., input: str = ..., enabled: bool = ...) -> None: ...
def __enter__(self): ...
def __exit__(self, exc_type: Any | None = ..., exc_value: Any | None = ..., traceback: Any | None = ...) -> None: ...
def get_lines(self): ...
def get_text(self): ...
def getvalue(self): ...

View File

@@ -1,5 +1,6 @@
from _typeshed import Self
from collections.abc import Callable, Mapping, Sequence
from types import TracebackType
from typing import Any, Generic, TypeVar, overload
from typing_extensions import Literal
@@ -163,7 +164,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: ...
@@ -175,7 +178,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

@@ -61,7 +61,9 @@ class Events(Generic[_T, _AbstractListener_T]):
start: Callable[[], None]
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> None: ...
def __iter__(self: Self) -> Self: ...
def __next__(self) -> _T: ...
def get(self, timeout: float | None = ...) -> _T | None: ...

View File

@@ -1,6 +1,7 @@
import threading
from _typeshed import Self, SupportsItems
from datetime import datetime, timedelta
from types import TracebackType
from typing import Any, Callable, ClassVar, Generic, Iterable, Iterator, Mapping, Pattern, Sequence, TypeVar, overload
from typing_extensions import Literal
@@ -320,7 +321,9 @@ class PubSub:
self, connection_pool, shard_hint: Any | None = ..., ignore_subscribe_messages: bool = ..., encoder: Any | None = ...
) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, exc_type: object, exc_value: object, traceback: object) -> None: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None
) -> None: ...
def __del__(self): ...
channels: Any
patterns: Any
@@ -698,6 +701,6 @@ class Monitor:
monitor_re: Pattern[str]
def __init__(self, connection_pool) -> None: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...
def next_command(self) -> dict[str, Any]: ...
def listen(self) -> Iterable[dict[str, Any]]: ...

View File

@@ -108,7 +108,7 @@ class Response:
def __nonzero__(self) -> bool: ...
def __iter__(self) -> Iterator[bytes]: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: Any) -> None: ...
def __exit__(self, *args: object) -> None: ...
@property
def next(self) -> PreparedRequest | None: ...
@property