Skip to content

Commit da3e69d

Browse files
authored
stdlib: Improve a bunch of __(a)exit__ methods (#7571)
1 parent 85f060b commit da3e69d

File tree

20 files changed

+47
-28
lines changed

20 files changed

+47
-28
lines changed

stdlib/_dummy_thread.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from types import TracebackType
12
from typing import Any, Callable, NoReturn
23

34
TIMEOUT_MAX: int
@@ -14,7 +15,7 @@ class LockType:
1415
def __init__(self) -> None: ...
1516
def acquire(self, waitflag: bool | None = ..., timeout: int = ...) -> bool: ...
1617
def __enter__(self, waitflag: bool | None = ..., timeout: int = ...) -> bool: ...
17-
def __exit__(self, typ: Any, val: Any, tb: Any) -> None: ...
18+
def __exit__(self, typ: type[BaseException] | None, val: BaseException | None, tb: TracebackType | None) -> None: ...
1819
def release(self) -> bool: ...
1920
def locked(self) -> bool: ...
2021

stdlib/asyncio/events.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class AbstractServer:
123123
def close(self) -> None: ...
124124
if sys.version_info >= (3, 7):
125125
async def __aenter__(self: Self) -> Self: ...
126-
async def __aexit__(self, *exc: Any) -> None: ...
126+
async def __aexit__(self, *exc: object) -> None: ...
127127
@abstractmethod
128128
def get_loop(self) -> AbstractEventLoop: ...
129129
@abstractmethod

stdlib/asyncio/locks.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ else:
2525
class _ContextManager:
2626
def __init__(self, lock: Lock | Semaphore) -> None: ...
2727
def __enter__(self) -> None: ...
28-
def __exit__(self, *args: Any) -> None: ...
28+
def __exit__(self, *args: object) -> None: ...
2929

3030
class _ContextManagerMixin:
3131
# Apparently this exists to *prohibit* use as a context manager.

stdlib/asyncio/windows_utils.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if sys.platform == "win32":
3131
def __del__(self) -> None: ...
3232

3333
def __enter__(self: Self) -> Self: ...
34-
def __exit__(self, t: type | None, v: BaseException | None, tb: TracebackType | None) -> None: ...
34+
def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ...
3535
@property
3636
def handle(self) -> int: ...
3737
def fileno(self) -> int: ...

stdlib/cProfile.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ class Profile:
3131
def runcall(self, __func: Callable[_P, _T], *args: _P.args, **kw: _P.kwargs) -> _T: ...
3232
if sys.version_info >= (3, 8):
3333
def __enter__(self: Self) -> Self: ...
34-
def __exit__(self, *exc_info: Any) -> None: ...
34+
def __exit__(self, *exc_info: object) -> None: ...
3535

3636
def label(code: str | CodeType) -> _Label: ... # undocumented

stdlib/calendar.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime
22
import sys
3+
from collections.abc import Iterable, Sequence
34
from time import struct_time
4-
from typing import Any, Iterable, Sequence
55
from typing_extensions import Literal
66

77
__all__ = [
@@ -106,7 +106,7 @@ class HTMLCalendar(Calendar):
106106
class different_locale:
107107
def __init__(self, locale: _LocaleType) -> None: ...
108108
def __enter__(self) -> None: ...
109-
def __exit__(self, *args: Any) -> None: ...
109+
def __exit__(self, *args: object) -> None: ...
110110

111111
class LocaleTextCalendar(TextCalendar):
112112
def __init__(self, firstweekday: int = ..., locale: _LocaleType | None = ...) -> None: ...

stdlib/cgi.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class FieldStorage:
127127
separator: str = ...,
128128
) -> None: ...
129129
def __enter__(self: Self) -> Self: ...
130-
def __exit__(self, *args: Any) -> None: ...
130+
def __exit__(self, *args: object) -> None: ...
131131
def __iter__(self) -> Iterator[str]: ...
132132
def __getitem__(self, key: str) -> Any: ...
133133
def getvalue(self, key: str, default: Any = ...) -> Any: ...

stdlib/concurrent/futures/_base.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from _typeshed import Self
44
from abc import abstractmethod
55
from collections.abc import Container, Iterable, Iterator, Sequence
66
from logging import Logger
7+
from types import TracebackType
78
from typing import Any, Callable, Generic, Protocol, TypeVar, overload
89
from typing_extensions import Literal, ParamSpec, SupportsIndex
910

@@ -73,7 +74,9 @@ class Executor:
7374
def shutdown(self, wait: bool = ...) -> None: ...
7475

7576
def __enter__(self: Self) -> Self: ...
76-
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool | None: ...
77+
def __exit__(
78+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
79+
) -> bool | None: ...
7780

7881
def as_completed(fs: Iterable[Future[_T]], timeout: float | None = ...) -> Iterator[Future[_T]]: ...
7982

@@ -127,4 +130,4 @@ class _AcquireFutures:
127130
futures: Iterable[Future[Any]]
128131
def __init__(self, futures: Iterable[Future[Any]]) -> None: ...
129132
def __enter__(self) -> None: ...
130-
def __exit__(self, *args: Any) -> None: ...
133+
def __exit__(self, *args: object) -> None: ...

stdlib/contextlib.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ if sys.version_info >= (3, 10):
217217
@overload
218218
def __init__(self: nullcontext[_T], enter_result: _T) -> None: ...
219219
def __enter__(self) -> _T: ...
220-
def __exit__(self, *exctype: Any) -> None: ...
220+
def __exit__(self, *exctype: object) -> None: ...
221221
async def __aenter__(self) -> _T: ...
222-
async def __aexit__(self, *exctype: Any) -> None: ...
222+
async def __aexit__(self, *exctype: object) -> None: ...
223223

224224
elif sys.version_info >= (3, 7):
225225
class nullcontext(AbstractContextManager[_T]):
@@ -229,7 +229,7 @@ elif sys.version_info >= (3, 7):
229229
@overload
230230
def __init__(self: nullcontext[_T], enter_result: _T) -> None: ...
231231
def __enter__(self) -> _T: ...
232-
def __exit__(self, *exctype: Any) -> None: ...
232+
def __exit__(self, *exctype: object) -> None: ...
233233

234234
if sys.version_info >= (3, 11):
235235
_T_fd_or_any_path = TypeVar("_T_fd_or_any_path", bound=int | StrOrBytesPath)

stdlib/fileinput.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
from _typeshed import Self, StrOrBytesPath
3+
from types import TracebackType
34
from typing import IO, Any, AnyStr, Callable, Generic, Iterable, Iterator
45

56
__all__ = [
@@ -98,7 +99,9 @@ class FileInput(Iterator[AnyStr], Generic[AnyStr]):
9899
def __del__(self) -> None: ...
99100
def close(self) -> None: ...
100101
def __enter__(self: Self) -> Self: ...
101-
def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ...
102+
def __exit__(
103+
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
104+
) -> None: ...
102105
def __iter__(self: Self) -> Self: ...
103106
def __next__(self) -> AnyStr: ...
104107
if sys.version_info < (3, 11):

0 commit comments

Comments
 (0)