Skip to content

False Context manager 'async_generator' doesn't implement __enter__ and __exit__ #10408

@davetapley

Description

@davetapley

Bug description

# repro.py

# inspired by:
# https://docs.python.org/3/library/contextlib.html#contextlib.asynccontextmanager

import time
from contextlib import asynccontextmanager


@asynccontextmanager
async def timeit():
    now = time.monotonic()
    try:
        yield
    finally:
        print(f'it took {time.monotonic() - now}s to run')


with timeit():
    print('hello world')

Configuration

Command used

pylint repro.py

Pylint output

repro.py:14:0: E1129: Context manager 'async_generator' doesn't implement __enter__ and __exit__. (not-context-manager)

Expected behavior

No error.

Pylint version

pylint 3.3.1
astroid 3.3.10
Python 3.12.2 (main, Feb 25 2024, 04:38:01) [Clang 17.0.6 ]

OS / Environment

No response

Additional dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    Enhancement ✨Improvement to a componentNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions