From 1f58890b3ea7a8683bc21594a7dc773443102893 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 17 Jan 2019 09:07:11 -0800 Subject: Set the proper scope for `async def` --- pyflakes/checker.py | 2 ++ pyflakes/test/test_type_annotations.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/pyflakes/checker.py b/pyflakes/checker.py index 4c18042..e94bc71 100644 --- a/pyflakes/checker.py +++ b/pyflakes/checker.py @@ -619,6 +619,8 @@ class Checker(object): ast.GeneratorExp: GeneratorScope, ast.DictComp: GeneratorScope, } + if PY35_PLUS: + _ast_node_scope[ast.AsyncFunctionDef] = FunctionScope, nodeDepth = 0 offset = None diff --git a/pyflakes/test/test_type_annotations.py b/pyflakes/test/test_type_annotations.py index e828412..1ed676b 100644 --- a/pyflakes/test/test_type_annotations.py +++ b/pyflakes/test/test_type_annotations.py @@ -179,6 +179,13 @@ class TestTypeAnnotations(TestCase): a: 'a: "A"' ''', m.ForwardAnnotationSyntaxError) + @skipIf(version_info < (3, 5), 'new in Python 3.5') + def test_annotated_async_def(self): + self.flakes(''' + class c: pass + async def func(c: c) -> None: pass + ''') + @skipIf(version_info < (3, 7), 'new in Python 3.7') def test_postponed_annotations(self): self.flakes(''' -- cgit v1.2.1