Skip to content

Commit 780bdcd

Browse files
authored
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
1 parent 0af480e commit 780bdcd

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pyflakes/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ class Checker(object):
793793
ast.DictComp: GeneratorScope,
794794
}
795795
if PY35_PLUS:
796-
_ast_node_scope[ast.AsyncFunctionDef] = FunctionScope,
796+
_ast_node_scope[ast.AsyncFunctionDef] = FunctionScope
797797

798798
nodeDepth = 0
799799
offset = None

pyflakes/test/test_code_segment.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
from sys import version_info
2+
13
from pyflakes import messages as m
24
from pyflakes.checker import (FunctionScope, ClassScope, ModuleScope,
35
Argument, FunctionDefinition, Assignment)
4-
from pyflakes.test.harness import TestCase
6+
from pyflakes.test.harness import TestCase, skipIf
57

68

79
class TestCodeSegments(TestCase):
@@ -124,3 +126,7 @@ def bar(f, g=1, *h, **i):
124126
self.assertIsInstance(function_scope_bar['g'], Argument)
125127
self.assertIsInstance(function_scope_bar['h'], Argument)
126128
self.assertIsInstance(function_scope_bar['i'], Argument)
129+
130+
@skipIf(version_info < (3, 5), 'new in Python 3.5')
131+
def test_scope_async_function(self):
132+
self.flakes('async def foo(): pass', is_segment=True)

0 commit comments

Comments
 (0)