Skip to content

Commit 610f267

Browse files
Update transaction.pyi (#268)
Make `transaction.atomic` compatible with `AbstractContextManager` protocol. Currently the following error is reported by pyright: ```python from contextlib import AbstractContextManager from django.db import transaction x: AbstractContextManager[None, None] = transaction.atomic() ``` ``` Type "Atomic" is not assignable to declared type "AbstractContextManager[None, None]" "Atomic" is incompatible with protocol "AbstractContextManager[None, None]" "__exit__" is an incompatible type Type "(exc_type: None, exc_value: None, traceback: None) -> None" is not assignable to type "(exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None, /) -> _ExitT_co@AbstractContextManager" Parameter 1: type "type[BaseException] | None" is incompatible with type "None" Type "type[BaseException] | None" is not assignable to type "None" Parameter 2: type "BaseException | None" is incompatible with type "None" Type "BaseException | None" is not assignable to type "None" Parameter 3: type "TracebackType | None" is incompatible with type "None" ```
1 parent 7f9bd0d commit 610f267

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

django-stubs/db/transaction.pyi

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ from collections.abc import Callable, Iterator
22
from contextlib import contextmanager
33
from typing import Any, TypeVar, overload
44

5+
from types import TracebackType
56
from django.db import ProgrammingError
67

78
class TransactionManagementError(ProgrammingError): ...
@@ -35,8 +36,12 @@ class Atomic:
3536
# When decorating, return the decorated function as-is, rather than clobbering it as ContextDecorator does.
3637
def __call__(self, func: _C) -> _C: ...
3738
def __enter__(self) -> None: ...
38-
def __exit__(self, exc_type: None, exc_value: None, traceback: None) -> None: ...
39-
39+
def __exit__(
40+
self,
41+
exc_type: type[BaseException] | None,
42+
exc_value: BaseException | None,
43+
traceback: TracebackType | None, /
44+
) -> None: ...
4045
# Bare decorator
4146
@overload
4247
def atomic(using: _C) -> _C: ...

0 commit comments

Comments
 (0)