Skip to content

Commit 52ec44f

Browse files
authored
Improve many __(a)exit__ annotations (#9696)
1 parent db82110 commit 52ec44f

File tree

45 files changed

+216
-81
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+216
-81
lines changed

stubs/JACK-Client/jack/__init__.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
from _typeshed import Unused
23
from collections.abc import Callable, Generator, Iterable, Iterator, Sequence
34
from typing import Any, NoReturn, overload
45
from typing_extensions import Literal, Self
@@ -80,7 +81,7 @@ class Client:
8081
session_id: str | None = ...,
8182
) -> None: ...
8283
def __enter__(self) -> Self: ...
83-
def __exit__(self, *args: object) -> None: ...
84+
def __exit__(self, *args: Unused) -> None: ...
8485
@property
8586
def name(self) -> str: ...
8687
@property

stubs/Pillow/PIL/Image.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from _typeshed import Incomplete, SupportsRead, SupportsWrite
1+
from _typeshed import Incomplete, SupportsRead, SupportsWrite, Unused
22
from collections.abc import Callable, Iterable, Iterator, MutableMapping, Sequence
33
from enum import IntEnum
44
from pathlib import Path
@@ -172,7 +172,7 @@ class Image:
172172
@property
173173
def size(self) -> tuple[int, int]: ...
174174
def __enter__(self) -> Self: ...
175-
def __exit__(self, *args: object) -> None: ...
175+
def __exit__(self, *args: Unused) -> None: ...
176176
def close(self) -> None: ...
177177
def __eq__(self, other: object) -> bool: ...
178178
def __getstate__(self) -> _ImageState: ...

stubs/Pillow/PIL/ImageFile.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from _typeshed import Incomplete
1+
from _typeshed import Incomplete, Unused
22
from typing import Any, NoReturn
33
from typing_extensions import Self
44

@@ -42,7 +42,7 @@ class Parser:
4242
decode: Any
4343
def feed(self, data) -> None: ...
4444
def __enter__(self) -> Self: ...
45-
def __exit__(self, *args: object) -> None: ...
45+
def __exit__(self, *args: Unused) -> None: ...
4646
def close(self) -> Image: ...
4747

4848
class PyCodecState:

stubs/Pillow/PIL/PdfParser.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import collections
22
from _typeshed import Incomplete
3+
from types import TracebackType
34
from typing import Any
5+
from typing_extensions import Literal
46

57
def encode_text(s: str) -> bytes: ...
68

@@ -95,7 +97,9 @@ class PdfParser:
9597
mode: str = ...,
9698
) -> None: ...
9799
def __enter__(self): ...
98-
def __exit__(self, exc_type, exc_value, traceback): ...
100+
def __exit__(
101+
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None
102+
) -> Literal[False]: ...
99103
def start_writing(self) -> None: ...
100104
def close_buf(self) -> None: ...
101105
def close(self) -> None: ...

stubs/Pillow/PIL/PngImagePlugin.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from _typeshed import Incomplete
1+
from _typeshed import Incomplete, Unused
22
from enum import IntEnum
33
from typing import Any, ClassVar
44
from typing_extensions import Literal
@@ -33,7 +33,7 @@ class ChunkStream:
3333
def __init__(self, fp) -> None: ...
3434
def read(self): ...
3535
def __enter__(self): ...
36-
def __exit__(self, *args) -> None: ...
36+
def __exit__(self, *args: Unused) -> None: ...
3737
def close(self) -> None: ...
3838
def push(self, cid, pos, length) -> None: ...
3939
def call(self, cid, pos, length): ...

stubs/Pillow/PIL/TarIO.pyi

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

34
from .ContainerIO import ContainerIO
@@ -6,5 +7,5 @@ class TarIO(ContainerIO):
67
fh: Any
78
def __init__(self, tarfile, file) -> None: ...
89
def __enter__(self): ...
9-
def __exit__(self, *args) -> None: ...
10+
def __exit__(self, *args: Unused) -> None: ...
1011
def close(self) -> None: ...

stubs/Pillow/PIL/TiffImagePlugin.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from _typeshed import Incomplete
22
from collections.abc import MutableMapping
33
from numbers import Rational
4+
from types import TracebackType
45
from typing import Any, ClassVar
56
from typing_extensions import Literal
67

@@ -171,7 +172,9 @@ class AppendingTiffWriter:
171172
def finalize(self) -> None: ...
172173
def newFrame(self) -> None: ...
173174
def __enter__(self): ...
174-
def __exit__(self, exc_type, exc_value, traceback): ...
175+
def __exit__(
176+
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None
177+
) -> Literal[False]: ...
175178
def tell(self): ...
176179
def seek(self, offset, whence=...): ...
177180
def goToEnd(self) -> None: ...

stubs/SQLAlchemy/sqlalchemy/ext/asyncio/base.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import abc
2+
from types import TracebackType
23

34
class ReversibleProxy: ...
45

@@ -8,7 +9,9 @@ class StartableContext(abc.ABC, metaclass=abc.ABCMeta):
89
def __await__(self): ...
910
async def __aenter__(self): ...
1011
@abc.abstractmethod
11-
async def __aexit__(self, type_, value, traceback): ...
12+
async def __aexit__(
13+
self, type_: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
14+
) -> None: ...
1215

1316
class ProxyComparable(ReversibleProxy):
1417
def __hash__(self) -> int: ...

stubs/SQLAlchemy/sqlalchemy/ext/asyncio/engine.pyi

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from _typeshed import Incomplete
2+
from types import TracebackType
23
from typing import Any
34

45
from .base import ProxyComparable, StartableContext
@@ -39,7 +40,9 @@ class AsyncConnection(ProxyComparable, StartableContext, AsyncConnectable):
3940
async def stream_scalars(self, statement, parameters: Incomplete | None = ..., execution_options=...): ...
4041
async def run_sync(self, fn, *arg, **kw): ...
4142
def __await__(self): ...
42-
async def __aexit__(self, type_, value, traceback) -> None: ...
43+
async def __aexit__(
44+
self, type_: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
45+
) -> None: ...
4346
# proxied from Connection
4447
dialect: Any
4548
@property
@@ -55,7 +58,9 @@ class AsyncEngine(ProxyComparable, AsyncConnectable):
5558
def __init__(self, conn) -> None: ...
5659
transaction: Any
5760
async def start(self, is_ctxmanager: bool = ...): ...
58-
async def __aexit__(self, type_, value, traceback) -> None: ...
61+
async def __aexit__(
62+
self, type_: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
63+
) -> None: ...
5964
sync_engine: Any
6065
def __init__(self, sync_engine) -> None: ...
6166
def begin(self): ...
@@ -91,4 +96,6 @@ class AsyncTransaction(ProxyComparable, StartableContext):
9196
async def rollback(self) -> None: ...
9297
async def commit(self) -> None: ...
9398
async def start(self, is_ctxmanager: bool = ...): ...
94-
async def __aexit__(self, type_, value, traceback) -> None: ...
99+
async def __aexit__(
100+
self, type_: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
101+
) -> None: ...

stubs/SQLAlchemy/sqlalchemy/ext/asyncio/session.pyi

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from _typeshed import Incomplete
2+
from types import TracebackType
23
from typing import Any
34
from typing_extensions import Self
45

@@ -55,7 +56,9 @@ class AsyncSession(ReversibleProxy):
5556
@classmethod
5657
async def close_all(cls): ...
5758
async def __aenter__(self) -> Self: ...
58-
async def __aexit__(self, type_, value, traceback) -> None: ...
59+
async def __aexit__(
60+
self, type_: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
61+
) -> None: ...
5962
# proxied from Session
6063
identity_map: Any
6164
autoflush: Any
@@ -92,7 +95,9 @@ class _AsyncSessionContextManager:
9295
def __init__(self, async_session) -> None: ...
9396
trans: Any
9497
async def __aenter__(self): ...
95-
async def __aexit__(self, type_, value, traceback) -> None: ...
98+
async def __aexit__(
99+
self, type_: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
100+
) -> None: ...
96101

97102
class AsyncSessionTransaction(ReversibleProxy, StartableContext):
98103
session: Any
@@ -104,7 +109,9 @@ class AsyncSessionTransaction(ReversibleProxy, StartableContext):
104109
async def rollback(self) -> None: ...
105110
async def commit(self) -> None: ...
106111
async def start(self, is_ctxmanager: bool = ...): ...
107-
async def __aexit__(self, type_, value, traceback) -> None: ...
112+
async def __aexit__(
113+
self, type_: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
114+
) -> None: ...
108115

109116
def async_object_session(instance): ...
110117
def async_session(session): ...

stubs/SQLAlchemy/sqlalchemy/orm/session.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from _typeshed import Incomplete
22
from collections.abc import Mapping
3+
from types import TracebackType
34
from typing import Any, TypeVar, overload
45
from typing_extensions import Self
56

@@ -107,7 +108,9 @@ class Session(_SessionClassMethods):
107108
) -> None: ...
108109
connection_callable: Any
109110
def __enter__(self) -> Self: ...
110-
def __exit__(self, type_, value, traceback) -> None: ...
111+
def __exit__(
112+
self, type_: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
113+
) -> None: ...
111114
@property
112115
def transaction(self): ...
113116
def in_transaction(self): ...
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
from types import TracebackType
12
from typing import Any
23

34
class _AsyncGeneratorContextManager:
45
gen: Any
56
__doc__: Any
67
def __init__(self, func, args, kwds) -> None: ...
78
async def __aenter__(self): ...
8-
async def __aexit__(self, typ, value, traceback): ...
9+
async def __aexit__(
10+
self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
11+
) -> bool | None: ...
912

1013
def asynccontextmanager(func): ...

stubs/SQLAlchemy/sqlalchemy/util/_concurrency_py3k.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio as asyncio
2+
from _typeshed import Unused
23
from collections.abc import Callable, Coroutine
34
from typing import Any
45

@@ -13,6 +14,6 @@ class AsyncAdaptedLock:
1314
@memoized_property
1415
def mutex(self): ...
1516
def __enter__(self): ...
16-
def __exit__(self, *arg, **kw) -> None: ...
17+
def __exit__(self, *arg: Unused, **kw: Unused) -> None: ...
1718

1819
def get_event_loop(): ...

stubs/SQLAlchemy/sqlalchemy/util/compat.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import itertools
55
import operator
66
import pickle as pickle
77
import threading as threading
8-
from _typeshed import Incomplete
8+
from _typeshed import Incomplete, Unused
99
from abc import ABC as ABC
1010
from datetime import timezone as timezone
1111
from functools import reduce as reduce
@@ -53,7 +53,7 @@ class nullcontext:
5353
enter_result: Any
5454
def __init__(self, enter_result: Incomplete | None = ...) -> None: ...
5555
def __enter__(self): ...
56-
def __exit__(self, *excinfo) -> None: ...
56+
def __exit__(self, *excinfo: Unused) -> None: ...
5757

5858
def inspect_getfullargspec(func): ...
5959
def importlib_metadata_get(group): ...

stubs/SQLAlchemy/sqlalchemy/util/langhelpers.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from _typeshed import Incomplete, Unused
22
from collections.abc import Callable
3+
from types import TracebackType
34
from typing import Any, Generic, TypeVar, overload
45
from typing_extensions import Self
56

@@ -13,7 +14,9 @@ class safe_reraise:
1314
warn_only: Any
1415
def __init__(self, warn_only: bool = ...) -> None: ...
1516
def __enter__(self) -> None: ...
16-
def __exit__(self, type_, value, traceback) -> None: ...
17+
def __exit__(
18+
self, type_: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
19+
) -> None: ...
1720

1821
def walk_subclasses(cls) -> None: ...
1922
def string_or_unprintable(element): ...

stubs/aws-xray-sdk/aws_xray_sdk/core/async_recorder.pyi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from _typeshed import Incomplete
2+
from types import TracebackType
23

34
from .models.segment import SegmentContextManager as SegmentContextManager
45
from .models.subsegment import (
@@ -11,12 +12,16 @@ from .utils import stacktrace as stacktrace
1112

1213
class AsyncSegmentContextManager(SegmentContextManager):
1314
async def __aenter__(self): ...
14-
async def __aexit__(self, exc_type, exc_val, exc_tb): ...
15+
async def __aexit__(
16+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
17+
) -> None: ...
1518

1619
class AsyncSubsegmentContextManager(SubsegmentContextManager):
1720
async def __call__(self, wrapped, instance, args, kwargs): ...
1821
async def __aenter__(self): ...
19-
async def __aexit__(self, exc_type, exc_val, exc_tb): ...
22+
async def __aexit__(
23+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
24+
) -> None: ...
2025

2126
class AsyncAWSXRayRecorder(AWSXRayRecorder):
2227
def capture_async(self, name: Incomplete | None = ...): ...

stubs/aws-xray-sdk/aws_xray_sdk/core/models/segment.pyi

Lines changed: 4 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
23

34
from ..exceptions.exceptions import SegmentNameMissingException as SegmentNameMissingException
@@ -16,7 +17,9 @@ class SegmentContextManager:
1617
segment: Segment
1718
def __init__(self, recorder: AWSXRayRecorder, name: str | None = ..., **segment_kwargs) -> None: ...
1819
def __enter__(self): ...
19-
def __exit__(self, exc_type, exc_val, exc_tb) -> None: ...
20+
def __exit__(
21+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
22+
) -> None: ...
2023

2124
class Segment(Entity):
2225
trace_id: str | None

stubs/aws-xray-sdk/aws_xray_sdk/core/models/subsegment.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import time
22
from _typeshed import Incomplete
3+
from types import TracebackType
34
from typing import Any
45

56
from ...core import AWSXRayRecorder
@@ -21,7 +22,9 @@ class SubsegmentContextManager:
2122
def __init__(self, recorder: AWSXRayRecorder, name: Incomplete | None = ..., **subsegment_kwargs) -> None: ...
2223
def __call__(self, wrapped, instance, args: list[Any], kwargs: dict[str, Any]): ...
2324
def __enter__(self) -> Subsegment: ...
24-
def __exit__(self, exc_type, exc_val, exc_tb) -> None: ...
25+
def __exit__(
26+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
27+
) -> None: ...
2528

2629
class Subsegment(Entity):
2730
parent_segment: Segment

stubs/cachetools/cachetools/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from _typeshed import IdentityFunction
1+
from _typeshed import IdentityFunction, Unused
22
from collections.abc import Callable, Iterator, MutableMapping, Sequence
33
from contextlib import AbstractContextManager
44
from typing import Any, Generic, TypeVar, overload
@@ -66,7 +66,7 @@ class _TimedCache(Cache[_KT, _VT]):
6666
def __init__(self, timer: Callable[[], float]) -> None: ...
6767
def __call__(self) -> float: ...
6868
def __enter__(self) -> float: ...
69-
def __exit__(self, *exc: object) -> None: ...
69+
def __exit__(self, *exc: Unused) -> None: ...
7070

7171
@property
7272
def timer(self) -> _Timer: ...

stubs/caldav/caldav/davclient.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from collections.abc import Iterable, Mapping
2+
from types import TracebackType
23
from typing import Any
34
from typing_extensions import Self, TypeAlias
45
from urllib.parse import ParseResult, SplitResult
@@ -50,7 +51,9 @@ class DAVClient:
5051
ssl_cert: str | tuple[str, str] | None = ...,
5152
) -> None: ...
5253
def __enter__(self) -> Self: ...
53-
def __exit__(self, exc_type: object, exc_value: object, traceback: object) -> None: ...
54+
def __exit__(
55+
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None
56+
) -> None: ...
5457
def principal(self, *, url: str | ParseResult | SplitResult | URL | None = ...) -> Principal: ...
5558
def calendar(
5659
self,

stubs/cffi/_cffi_backend.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class _CDataBase:
6969
def __dir__(self): ...
7070
def __enter__(self): ...
7171
def __eq__(self, other): ...
72-
def __exit__(self, type, value, traceback): ...
72+
def __exit__(self, type: type[BaseException] | None, value: BaseException | None, traceback: types.TracebackType | None): ...
7373
def __float__(self) -> float: ...
7474
def __ge__(self, other): ...
7575
def __getitem__(self, index): ...

stubs/humanfriendly/humanfriendly/testing.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class MockedProgram(CustomSearchPath):
6565
program_signal_file: Any
6666
def __init__(self, name, returncode: int = ..., script: Incomplete | None = ...) -> None: ...
6767
def __enter__(self): ...
68-
def __exit__(self, *args, **kw): ...
68+
def __exit__(self, *args: object, **kw: object): ...
6969

7070
class CaptureOutput(ContextManager):
7171
stdin: Any

0 commit comments

Comments
 (0)