Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not-async-context-manager false positive: wrapped asynccontextmanager #3862

Closed
belm0 opened this issue Sep 25, 2020 · 3 comments · Fixed by #3996
Closed

not-async-context-manager false positive: wrapped asynccontextmanager #3862

belm0 opened this issue Sep 25, 2020 · 3 comments · Fixed by #3996
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code

Comments

@belm0
Copy link
Contributor

belm0 commented Sep 25, 2020

Steps to reproduce

def foo():
    @asynccontextmanager
    async def wrapper(*args, **kwargs):
        pass
    return wrapper

async with foo():
    pass
E1701: Async context manager 'wrapper' doesn't implement __aenter__ and __aexit__. (not-async-context-manager)

The troubling thing is that foo() is part of a public API, which means every project using it would need to suppress not-async-context-manager.

pylint --version output

pylint 2.6.0
astroid 2.4.2
Python 3.8.2 (default, Jun 15 2020, 10:47:09)
[Clang 9.0.0 (clang-900.0.39.2)]

@belm0
Copy link
Contributor Author

belm0 commented Sep 28, 2020

This check is similarly confused by context manager provided by decorators on Trio's CapacityLimiter:

https://github.com/python-trio/trio/blob/cabdd9fb69bcd9e9283ec3eda343a1904c81b528/trio/_sync.py#L101-L103

(that may be covered by existing contextmanager-decorators option, though I haven't checked to see if it correctly supports async context managers)

@ToucanBran
Copy link

can confirm also facing the same issue

pylint 2.6.0
astroid 2.4.2
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)]

@hippo91
Copy link
Contributor

hippo91 commented Oct 24, 2020

@belm0, @ToucanBran thank for the report.
I can reproduce it with the following code:

#pylint:disable=missing-module-docstring,missing-function-docstring,blacklisted-name
#pylint:disable=unused-argument
from contextlib import asynccontextmanager

def foo():
    @asynccontextmanager
    async def wrapper(*args, **kwargs):
        pass
    return wrapper

async def toto():
    async with foo():
        pass

@hippo91 hippo91 added Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code labels Oct 24, 2020
PCManticore added a commit that referenced this issue Dec 28, 2020
PCManticore added a commit that referenced this issue Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
3 participants