Skip to content

transaction.atomic is incompatible with ExitStack().enter_context #410

Closed
@flaeppe

Description

@flaeppe

Bug report

django.db.transaction.atomic is incompatible with contextlib.ExitStack().enter_context

What's wrong

Repro case:

from contextlib import ExitStack
from django.db import transaction

with ExitStack() as stack:
    stack.enter_context(transaction.atomic())

Causes:

error: Argument 1 to "enter_context" of "ExitStack" has incompatible type "Atomic"; expected "ContextManager[<nothing>]"  [arg-type]

How is that should be

transaction.atomic() should be accepted as a valid argument to stack.enter_context as it declares the expected __enter__ and __exit__ methods.

System information

  • OS:
  • python version: 3.8.0
  • django version: 3.0.7
  • mypy version: 0.770
  • django-stubs version: 1.5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions