summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2018-09-05 09:26:52 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2018-09-05 09:26:52 +0200
commit2a8ff2c8994d60377d4359470c767dea744d8259 (patch)
treeedf55a2c70d7a8fab9b76b03000ff286c6271f9b
parentc8c5e265afe4cd64788ac1dd910c577e165dee31 (diff)
downloadpylint-git-2a8ff2c8994d60377d4359470c767dea744d8259.tar.gz
``assignment-from-no-return`` is not emitted for coroutines.
The reason for that is that the function calls actually are returning something, a future object that needs to be consumed through the event loop, so emitting this check for coroutines is wrong. Close #1715
-rw-r--r--ChangeLog3
-rw-r--r--pylint/checkers/typecheck.py3
-rw-r--r--pylint/test/functional/assignment_from_no_return_py3.py28
-rw-r--r--pylint/test/functional/assignment_from_no_return_py3.rc2
-rw-r--r--pylint/test/functional/assignment_from_no_return_py3.txt0
5 files changed, 35 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 26f534b69..2010ca015 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,9 @@ What's New in Pylint 2.2?
Release date: TBA
+ * ``assignment-from-no-return`` is not emitted for coroutines.
+
+ Close #1715
* Report format string type mismatches.
diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py
index 2bb224d2f..fff87753b 100644
--- a/pylint/checkers/typecheck.py
+++ b/pylint/checkers/typecheck.py
@@ -830,7 +830,8 @@ accessed. Python regular expressions are accepted.'}
and not function_node.decorators):
return
if (function_node.is_generator()
- or function_node.is_abstract(pass_is_abstract=False)):
+ or function_node.is_abstract(pass_is_abstract=False)
+ or isinstance(function_node, astroid.AsyncFunctionDef)):
return
returns = list(function_node.nodes_of_class(astroid.Return,
skip_klass=astroid.FunctionDef))
diff --git a/pylint/test/functional/assignment_from_no_return_py3.py b/pylint/test/functional/assignment_from_no_return_py3.py
new file mode 100644
index 000000000..2339706ce
--- /dev/null
+++ b/pylint/test/functional/assignment_from_no_return_py3.py
@@ -0,0 +1,28 @@
+# pylint: disable=missing-docstring
+
+import asyncio
+
+
+async def bla1():
+ await asyncio.sleep(1)
+
+
+async def bla2():
+ await asyncio.sleep(2)
+
+
+async def combining_coroutine1():
+ await bla1()
+ await bla2()
+
+
+async def combining_coroutine2():
+ future1 = bla1()
+ future2 = bla2()
+ await asyncio.gather(future1, future2)
+
+
+def do_stuff():
+ loop = asyncio.get_event_loop()
+ loop.run_until_complete(combining_coroutine1())
+ loop.run_until_complete(combining_coroutine2())
diff --git a/pylint/test/functional/assignment_from_no_return_py3.rc b/pylint/test/functional/assignment_from_no_return_py3.rc
new file mode 100644
index 000000000..1450ccc64
--- /dev/null
+++ b/pylint/test/functional/assignment_from_no_return_py3.rc
@@ -0,0 +1,2 @@
+[testoptions]
+min_pyver=3.6 \ No newline at end of file
diff --git a/pylint/test/functional/assignment_from_no_return_py3.txt b/pylint/test/functional/assignment_from_no_return_py3.txt
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/pylint/test/functional/assignment_from_no_return_py3.txt