diff options
author | yushao2 <36848472+yushao2@users.noreply.github.com> | 2021-06-10 04:02:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-09 22:02:23 +0200 |
commit | 2a186f4afd3e507c33fa387dfa2d9cfefd795b49 (patch) | |
tree | 1d31923a4532555064b7a0f40a503f461019e3fa /tests | |
parent | 78de5c49a61c8a3f2ca9930956a7df8e8f3ccae0 (diff) | |
download | pylint-git-2a186f4afd3e507c33fa387dfa2d9cfefd795b49.tar.gz |
Implemented new checker await-outside-async (#4514)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functional/a/await_outside_async.py | 30 | ||||
-rw-r--r-- | tests/functional/a/await_outside_async.rc | 2 | ||||
-rw-r--r-- | tests/functional/a/await_outside_async.txt | 2 |
3 files changed, 34 insertions, 0 deletions
diff --git a/tests/functional/a/await_outside_async.py b/tests/functional/a/await_outside_async.py new file mode 100644 index 000000000..2bc126761 --- /dev/null +++ b/tests/functional/a/await_outside_async.py @@ -0,0 +1,30 @@ +# pylint: disable=missing-docstring,unused-variable +import asyncio + +async def nested(): + return 42 + +async def main(): + nested() + print(await nested()) # This is okay + +def not_async(): + print(await nested()) # [await-outside-async] + + +async def func(i): + return i**2 + +async def okay_function(): + var = [await func(i) for i in range(5)] # This should be okay + + +# Test nested functions +async def func2(): + def inner_func(): + await asyncio.sleep(1) # [await-outside-async] + + +def outer_func(): + async def inner_func(): + await asyncio.sleep(1) diff --git a/tests/functional/a/await_outside_async.rc b/tests/functional/a/await_outside_async.rc new file mode 100644 index 000000000..a17bb22da --- /dev/null +++ b/tests/functional/a/await_outside_async.rc @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=3.7 diff --git a/tests/functional/a/await_outside_async.txt b/tests/functional/a/await_outside_async.txt new file mode 100644 index 000000000..e38a51cd3 --- /dev/null +++ b/tests/functional/a/await_outside_async.txt @@ -0,0 +1,2 @@ +await-outside-async:12:10:not_async:'await' should be used within an async function +await-outside-async:25:8:func2.inner_func:'await' should be used within an async function |