Skip to content

Commit be5724c

Browse files
Spell out the context-manager dunder argument types
Replace *args: Any catch-alls on __exit__ / __aexit__ with the typed three-argument signature (exc_type, exc_val, exc_tb). The runtime behaviour is unchanged, but callers and mypy now see the standard context-manager contract instead of a variadic Any-bag. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 915dcd9 commit be5724c

4 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/dqlitedbapi/aio/connection.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import asyncio
44
import contextlib
55
import math
6+
from types import TracebackType
67
from typing import Any
78

89
import dqliteclient.exceptions as _client_exc
@@ -180,7 +181,12 @@ async def __aenter__(self) -> "AsyncConnection":
180181
await self.connect()
181182
return self
182183

183-
async def __aexit__(self, exc_type: type[BaseException] | None, *args: Any) -> None:
184+
async def __aexit__(
185+
self,
186+
exc_type: type[BaseException] | None,
187+
exc_val: BaseException | None,
188+
exc_tb: TracebackType | None,
189+
) -> None:
184190
if self._async_conn is None:
185191
await self.close()
186192
return

src/dqlitedbapi/aio/cursor.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Async cursor implementation for dqlite."""
22

33
from collections.abc import Sequence
4+
from types import TracebackType
45
from typing import TYPE_CHECKING, Any
56

67
from dqlitedbapi.cursor import (
@@ -288,5 +289,10 @@ async def __anext__(self) -> tuple[Any, ...]:
288289
async def __aenter__(self) -> "AsyncCursor":
289290
return self
290291

291-
async def __aexit__(self, *args: Any) -> None:
292+
async def __aexit__(
293+
self,
294+
exc_type: type[BaseException] | None,
295+
exc_val: BaseException | None,
296+
exc_tb: TracebackType | None,
297+
) -> None:
292298
await self.close()

src/dqlitedbapi/connection.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import threading
77
import warnings
88
import weakref
9+
from types import TracebackType
910
from typing import Any
1011

1112
import dqliteclient.exceptions as _client_exc
@@ -359,7 +360,12 @@ def __repr__(self) -> str:
359360
def __enter__(self) -> "Connection":
360361
return self
361362

362-
def __exit__(self, exc_type: type[BaseException] | None, *args: Any) -> None:
363+
def __exit__(
364+
self,
365+
exc_type: type[BaseException] | None,
366+
exc_val: BaseException | None,
367+
exc_tb: TracebackType | None,
368+
) -> None:
363369
# If no query has ever run, there's no transaction to commit or
364370
# roll back — just close.
365371
if self._async_conn is None:

src/dqlitedbapi/cursor.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""PEP 249 Cursor implementation for dqlite."""
22

33
from collections.abc import Callable, Coroutine, Mapping, Sequence
4+
from types import TracebackType
45
from typing import TYPE_CHECKING, Any
56

67
import dqliteclient.exceptions as _client_exc
@@ -451,5 +452,10 @@ def __next__(self) -> tuple[Any, ...]:
451452
def __enter__(self) -> "Cursor":
452453
return self
453454

454-
def __exit__(self, *args: Any) -> None:
455+
def __exit__(
456+
self,
457+
exc_type: type[BaseException] | None,
458+
exc_val: BaseException | None,
459+
exc_tb: TracebackType | None,
460+
) -> None:
455461
self.close()

0 commit comments

Comments
 (0)