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

asyncio.coroutine not detected correctly on instance method invocation #3583

Closed
ncoghlan opened this issue May 4, 2020 · 0 comments · Fixed by pylint-dev/astroid#799
Closed
Assignees
Labels

Comments

@ncoghlan
Copy link

ncoghlan commented May 4, 2020

Similar to #996, I'm getting an incorrect not-an-iterable error on an @asyncio.coroutine call. In this case, the error seems to be a more convoluted one related to a particular combination of circumstances leading to the method definition not being detected as a coroutine.

The minimal reproducer I've come up with (along with a couple of examples of cases that work as expected) is the following:

import asyncio

@asyncio.coroutine
def _func_detected_as_cr():
    if (yield from asyncio.sleep(0.01)):
        return

class Example():

    @asyncio.coroutine
    def _method_detected_as_cr(self):
        if (yield from asyncio.sleep(0.01)):
            pass

    @asyncio.coroutine
    def passes_pylint_check_1(self):
        yield from _func_detected_as_cr()

    @asyncio.coroutine
    def passes_pylint_check_2(self):
        yield from self._method_detected_as_cr()

    @asyncio.coroutine
    def _method_not_detected_as_cr(self):
        if (yield from asyncio.sleep(0.01)):
            pass
            return

    @asyncio.coroutine
    def fails_pylint_check(self):
        yield from self._method_not_detected_as_cr()

That gives the result:

$ pylint -E spurious_pylint_E1133.py
************* Module spurious_pylint_E1133
spurious_pylint_E1133.py:31:19: E1133: Non-iterable value self._method_not_detected_as_cr() is used in an iterating context (not-an-iterable)```

As shown in the reproducer, the same code in a top level function gets correctly detected as a coroutine, while similar code is correctly detected as long as it doesn't have an early return in the if statement body.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants