summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Law <PeterJCLaw@gmail.com>2020-03-13 15:50:13 +0000
committerGitHub <noreply@github.com>2020-03-13 08:50:13 -0700
commit780bdcd6fe10f34f1b3eff1c255ca50ef3b94478 (patch)
tree500b9af1381baf19028f47b6fe7079f7dce1cc24
parent0af480e3351ae40b4ae7f3ce7272a46fd4265dbd (diff)
downloadpyflakes-780bdcd6fe10f34f1b3eff1c255ca50ef3b94478.tar.gz
Fix bug in async function scope checking (#511)
* Fix bug in async function scope checking Previously attempting to check an async function scoped tree would immediately error because tuples are not callable. The test added here is a direct copy of 'test_scope_function' as I'm not sure what (if anything) should specifically be tested for async functions, though it serves to prove the fix. * Skip async function test where it doesn't apply * Clarify that this is a smoke test for async function segments
-rw-r--r--pyflakes/checker.py2
-rw-r--r--pyflakes/test/test_code_segment.py8
2 files changed, 8 insertions, 2 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 351ab12..f886c26 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -793,7 +793,7 @@ class Checker(object):
ast.DictComp: GeneratorScope,
}
if PY35_PLUS:
- _ast_node_scope[ast.AsyncFunctionDef] = FunctionScope,
+ _ast_node_scope[ast.AsyncFunctionDef] = FunctionScope
nodeDepth = 0
offset = None
diff --git a/pyflakes/test/test_code_segment.py b/pyflakes/test/test_code_segment.py
index 5e53f8f..131a74d 100644
--- a/pyflakes/test/test_code_segment.py
+++ b/pyflakes/test/test_code_segment.py
@@ -1,7 +1,9 @@
+from sys import version_info
+
from pyflakes import messages as m
from pyflakes.checker import (FunctionScope, ClassScope, ModuleScope,
Argument, FunctionDefinition, Assignment)
-from pyflakes.test.harness import TestCase
+from pyflakes.test.harness import TestCase, skipIf
class TestCodeSegments(TestCase):
@@ -124,3 +126,7 @@ class TestCodeSegments(TestCase):
self.assertIsInstance(function_scope_bar['g'], Argument)
self.assertIsInstance(function_scope_bar['h'], Argument)
self.assertIsInstance(function_scope_bar['i'], Argument)
+
+ @skipIf(version_info < (3, 5), 'new in Python 3.5')
+ def test_scope_async_function(self):
+ self.flakes('async def foo(): pass', is_segment=True)