pylint
pylint copied to clipboard
Add new checks for the new coroutines added in PEP 492 and Python 3.5
Originally reported by: Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore)
Would be useful to have some of these at least:
- await accepts only an awaitable
- type error if await returns anything else than an iterator
- syntax error if await is used outside of an async def
- aenter and aexit must return an awaitable
- syntax error to use async with out side of async def
- error to pass an object without anter and aexit to async with
Similar to for async for.
- Bitbucket: https://bitbucket.org/logilab/pylint/issue/654
Also, make sure all parameters after async def are recognized. At the moment, Undefined variable errors are logged for the function parameters.
This was just reported by another user at #767 I'll have a look. Hopefully we'll release a bug fix in the following day(s).
@bradmcl For the record, https://github.com/PyCQA/pylint/commit/a249d45bc55e18c893fc7a645ab60bb00417d5c1 should fix your problems.
@PCManticore Confirmed, #767 fixes the issue here. Thanks!
Would be nice to add a milestone to this release, so people can see which version this fix will be included in.
Yup, added a milestone to the 2.0 release. Unfortunately, we don't know when that is going out, since the only people active are me and @ceridwen who is working more on astroid.
I almost submitted an issue for this but I believe it might be related, could you confirm? Seems to be related to the async keyword.
Steps to reproduce
- See attached gist link
- Run pylint on that code
Current behavior
Code: https://gist.github.com/stemid/d254194540ec1a1852727e10ca0465de
I get syntax error on line 51. If I remove that whole method the syntax error moves to the next method.
If I remove the above multi-line string there is no change in the issue.
If I add a new method above line 51 with just one argument (self) and immediate return the syntax error moves to this method. Indicating the issue is above but I can't figure it out.
Expected behavior
I'm not expecting a syntax error there.
pylint --version output
No config file found, using default configuration pylint 1.6.5, astroid 1.4.9 Python 2.7.13 (default, Jan 12 2017, 17:59:37) [GCC 6.3.1 20161221 (Red Hat 6.3.1-1)]
@stemid please re-run it on latest release (1.7.1 with astroid 1.5.2). It should work just fine.
@rogalski 1.7.1 worked much better, thanks.
is is a syntax error to have yield or yield from in a coroutine
This is not true anymore in Python 3.6 with PEP 525: https://www.python.org/dev/peps/pep-0525/
Although, yield from is expected to be never used, since there shouldn't be a reason to.
Thanks for the comment @xNinjaKittyx ! I removed that from the list, it's definitely not an authoritative list, since the issue was created long time ago. We'd definitely need to recheck what's possible and what's not in the recent releases.
- await accepts only an awaitable
- type error if await returns anything else than an iterator
- ~syntax error if await is used outside of an async def~
- aenter and aexit must return an awaitable
- syntax error to use async with out side of async def
- ~error to pass an object without anter and aexit to async with~