summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2019-09-30 15:27:57 -0700
committerGitHub <noreply@github.com>2019-09-30 15:27:57 -0700
commitee1eb0670a473a30f32208b7bd811282834486a6 (patch)
tree61dbf551131dc6d401c4f7af118423a05730fe0e
parent5ed30a6b9e4b9c1bb4042e5c5b3b506e52133da4 (diff)
downloadpyflakes-ee1eb0670a473a30f32208b7bd811282834486a6.tar.gz
Allow @overload on async functions as well (#472)
-rw-r--r--pyflakes/checker.py4
-rw-r--r--pyflakes/test/test_type_annotations.py18
2 files changed, 21 insertions, 1 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 44c6b25..eca2002 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -72,9 +72,11 @@ else:
if PY35_PLUS:
FOR_TYPES = (ast.For, ast.AsyncFor)
LOOP_TYPES = (ast.While, ast.For, ast.AsyncFor)
+ FUNCTION_TYPES = (ast.FunctionDef, ast.AsyncFunctionDef)
else:
FOR_TYPES = (ast.For,)
LOOP_TYPES = (ast.While, ast.For)
+ FUNCTION_TYPES = (ast.FunctionDef,)
# https://github.com/python/typed_ast/blob/1.4.0/ast27/Parser/tokenizer.c#L102-L104
TYPE_COMMENT_RE = re.compile(r'^#\s*type:\s*')
@@ -642,7 +644,7 @@ def is_typing_overload(value, scope_stack):
)
return (
- isinstance(value.source, ast.FunctionDef) and
+ isinstance(value.source, FUNCTION_TYPES) and
any(
is_typing_overload_decorator(dec)
for dec in value.source.decorator_list
diff --git a/pyflakes/test/test_type_annotations.py b/pyflakes/test/test_type_annotations.py
index 676a4a5..045c57a 100644
--- a/pyflakes/test/test_type_annotations.py
+++ b/pyflakes/test/test_type_annotations.py
@@ -56,6 +56,24 @@ class TestTypeAnnotations(TestCase):
return s
""")
+ @skipIf(version_info < (3, 5), 'new in Python 3.5')
+ def test_typingOverloadAsync(self):
+ """Allow intentional redefinitions via @typing.overload (async)"""
+ self.flakes("""
+ from typing import overload
+
+ @overload
+ async def f(s): # type: (None) -> None
+ pass
+
+ @overload
+ async def f(s): # type: (int) -> int
+ pass
+
+ async def f(s):
+ return s
+ """)
+
def test_overload_with_multiple_decorators(self):
self.flakes("""
from typing import overload