pylint icon indicating copy to clipboard operation
pylint copied to clipboard

Add new checks for the new coroutines added in PEP 492 and Python 3.5

Open pylint-bot opened this issue 10 years ago • 12 comments

Originally reported by: Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore)


Would be useful to have some of these at least:

  1. await accepts only an awaitable
  2. type error if await returns anything else than an iterator
  3. syntax error if await is used outside of an async def
  4. aenter and aexit must return an awaitable
  5. syntax error to use async with out side of async def
  6. 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

pylint-bot avatar Sep 29 '15 23:09 pylint-bot

Also, make sure all parameters after async def are recognized. At the moment, Undefined variable errors are logged for the function parameters.

bradm-pa avatar Jan 06 '16 20:01 bradm-pa

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).

PCManticore avatar Jan 06 '16 21:01 PCManticore

@bradmcl For the record, https://github.com/PyCQA/pylint/commit/a249d45bc55e18c893fc7a645ab60bb00417d5c1 should fix your problems.

PCManticore avatar Jan 09 '16 15:01 PCManticore

@PCManticore Confirmed, #767 fixes the issue here. Thanks!

bradm-pa avatar Jan 10 '16 01:01 bradm-pa

Would be nice to add a milestone to this release, so people can see which version this fix will be included in.

tobias47n9e avatar Mar 02 '16 22:03 tobias47n9e

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.

PCManticore avatar Mar 02 '16 23:03 PCManticore

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

  1. See attached gist link
  2. 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 avatar Apr 20 '17 21:04 stemid

@stemid please re-run it on latest release (1.7.1 with astroid 1.5.2). It should work just fine.

rogalski avatar Apr 20 '17 21:04 rogalski

@rogalski 1.7.1 worked much better, thanks.

stemid avatar Apr 21 '17 07:04 stemid

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.

xNinjaKittyx avatar Mar 02 '18 19:03 xNinjaKittyx

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.

PCManticore avatar Mar 05 '18 09:03 PCManticore

  1. await accepts only an awaitable
  2. type error if await returns anything else than an iterator
  3. ~syntax error if await is used outside of an async def~
  4. aenter and aexit must return an awaitable
  5. syntax error to use async with out side of async def
  6. ~error to pass an object without anter and aexit to async with~

yushao2 avatar Jun 10 '21 15:06 yushao2