Skip to content

Commit da3e69d

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

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):

stdlib/multiprocessing/sharedctypes.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from collections.abc import Callable, Iterable, Sequence
33
from ctypes import _CData, _SimpleCData, c_char
44
from multiprocessing.context import BaseContext
55
from multiprocessing.synchronize import _LockLike
6+
from types import TracebackType
67
from typing import Any, Generic, Protocol, TypeVar, overload
78
from typing_extensions import Literal
89

@@ -82,7 +83,9 @@ class SynchronizedBase(Generic[_CT]):
8283
def get_obj(self) -> _CT: ...
8384
def get_lock(self) -> _LockLike: ...
8485
def __enter__(self) -> bool: ...
85-
def __exit__(self, *args: Any) -> None: ...
86+
def __exit__(
87+
self, __exc_type: type[BaseException] | None, __exc_val: BaseException | None, __exc_tb: TracebackType | None
88+
) -> None: ...
8689

8790
class Synchronized(SynchronizedBase[_SimpleCData[_T]], Generic[_T]):
8891
value: _T

stdlib/nntplib.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class NNTP:
7373
timeout: float = ...,
7474
) -> None: ...
7575
def __enter__(self: Self) -> Self: ...
76-
def __exit__(self, *args: Any) -> None: ...
76+
def __exit__(self, *args: object) -> None: ...
7777
def getwelcome(self) -> str: ...
7878
def getcapabilities(self) -> dict[str, _list[str]]: ...
7979
def set_debuglevel(self, level: int) -> None: ...

stdlib/os/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ if sys.version_info >= (3, 8):
10211021
def __init__(self, path: str | None, cookie: _T, remove_dll_directory: Callable[[_T], Any]) -> None: ...
10221022
def close(self) -> None: ...
10231023
def __enter__(self: Self) -> Self: ...
1024-
def __exit__(self, *args: Any) -> None: ...
1024+
def __exit__(self, *args: object) -> None: ...
10251025

10261026
def add_dll_directory(path: str) -> _AddedDllDirectory: ...
10271027
if sys.platform == "linux":

stdlib/runpy.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ class _TempModule:
99
module: ModuleType
1010
def __init__(self, mod_name: str) -> None: ...
1111
def __enter__(self: Self) -> Self: ...
12-
def __exit__(self, *args: Any) -> None: ...
12+
def __exit__(self, *args: object) -> None: ...
1313

1414
class _ModifiedArgv0:
1515
value: Any
1616
def __init__(self, value: Any) -> None: ...
1717
def __enter__(self) -> None: ...
18-
def __exit__(self, *args: Any) -> None: ...
18+
def __exit__(self, *args: object) -> None: ...
1919

2020
def run_module(
2121
mod_name: str, init_globals: dict[str, Any] | None = ..., run_name: str | None = ..., alter_sys: bool = ...

stdlib/selectors.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class BaseSelector(metaclass=ABCMeta):
2727
@abstractmethod
2828
def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ...
2929
def __enter__(self: Self) -> Self: ...
30-
def __exit__(self, *args: Any) -> None: ...
30+
def __exit__(self, *args: object) -> None: ...
3131

3232
class SelectSelector(BaseSelector):
3333
def register(self, fileobj: FileDescriptorLike, events: _EventMask, data: Any = ...) -> SelectorKey: ...

stdlib/sqlite3/dbapi2.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
from _typeshed import Self, StrOrBytesPath
33
from datetime import date, datetime, time
4+
from types import TracebackType
45
from typing import Any, Callable, Generator, Iterable, Iterator, Protocol, TypeVar
56
from typing_extensions import Literal, final
67

@@ -183,7 +184,9 @@ class Connection:
183184

184185
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
185186
def __enter__(self: Self) -> Self: ...
186-
def __exit__(self, __type: type | None, __value: BaseException | None, __traceback: Any | None) -> Literal[False]: ...
187+
def __exit__(
188+
self, __type: type[BaseException] | None, __value: BaseException | None, __traceback: TracebackType | None
189+
) -> Literal[False]: ...
187190

188191
class Cursor(Iterator[Any]):
189192
arraysize: Any

stdlib/sunau.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class _sunau_params(NamedTuple):
3333
class Au_read:
3434
def __init__(self, f: _File) -> None: ...
3535
def __enter__(self: Self) -> Self: ...
36-
def __exit__(self, *args: Any) -> None: ...
36+
def __exit__(self, *args: object) -> None: ...
3737
def getfp(self) -> IO[bytes] | None: ...
3838
def rewind(self) -> None: ...
3939
def close(self) -> None: ...
@@ -53,7 +53,7 @@ class Au_read:
5353
class Au_write:
5454
def __init__(self, f: _File) -> None: ...
5555
def __enter__(self: Self) -> Self: ...
56-
def __exit__(self, *args: Any) -> None: ...
56+
def __exit__(self, *args: object) -> None: ...
5757
def setnchannels(self, nchannels: int) -> None: ...
5858
def getnchannels(self) -> int: ...
5959
def setsampwidth(self, sampwidth: int) -> None: ...

stdlib/telnetlib.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import socket
22
from _typeshed import Self
3+
from types import TracebackType
34
from typing import Any, Callable, Match, Pattern, Sequence
45

56
__all__ = ["Telnet"]
@@ -113,4 +114,6 @@ class Telnet:
113114
self, list: Sequence[Pattern[bytes] | bytes], timeout: float | None = ...
114115
) -> tuple[int, Match[bytes] | None, bytes]: ...
115116
def __enter__(self: Self) -> Self: ...
116-
def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ...
117+
def __exit__(
118+
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
119+
) -> None: ...

stdlib/unittest/mock.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
from _typeshed import Self
33
from contextlib import _GeneratorContextManager
4+
from types import TracebackType
45
from typing import Any, Awaitable, Callable, Generic, Iterable, Mapping, Sequence, TypeVar, overload
56
from typing_extensions import Literal
67

@@ -263,7 +264,9 @@ class _patch(Generic[_T]):
263264
temp_original: Any
264265
is_local: bool
265266
def __enter__(self) -> _T: ...
266-
def __exit__(self, *exc_info: Any) -> None: ...
267+
def __exit__(
268+
self, __exc_type: type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
269+
) -> None: ...
267270
def start(self) -> _T: ...
268271
def stop(self) -> None: ...
269272

@@ -275,7 +278,7 @@ class _patch_dict:
275278
def __call__(self, f: Any) -> Any: ...
276279
def decorate_class(self, klass: Any) -> Any: ...
277280
def __enter__(self) -> Any: ...
278-
def __exit__(self, *args: Any) -> Any: ...
281+
def __exit__(self, *args: object) -> Any: ...
279282
start: Any
280283
stop: Any
281284

stdlib/wave.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class _wave_params(NamedTuple):
2525
class Wave_read:
2626
def __init__(self, f: _File) -> None: ...
2727
def __enter__(self: Self) -> Self: ...
28-
def __exit__(self, *args: Any) -> None: ...
28+
def __exit__(self, *args: object) -> None: ...
2929
def getfp(self) -> BinaryIO | None: ...
3030
def rewind(self) -> None: ...
3131
def close(self) -> None: ...
@@ -45,7 +45,7 @@ class Wave_read:
4545
class Wave_write:
4646
def __init__(self, f: _File) -> None: ...
4747
def __enter__(self: Self) -> Self: ...
48-
def __exit__(self, *args: Any) -> None: ...
48+
def __exit__(self, *args: object) -> None: ...
4949
def setnchannels(self, nchannels: int) -> None: ...
5050
def getnchannels(self) -> int: ...
5151
def setsampwidth(self, sampwidth: int) -> None: ...

0 commit comments

Comments
 (0)