Skip to content

Commit ee1eb06

Browse files
authored
Allow @overload on async functions as well (#472)
1 parent 5ed30a6 commit ee1eb06

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pyflakes/checker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ def getAlternatives(n):
7272
if PY35_PLUS:
7373
FOR_TYPES = (ast.For, ast.AsyncFor)
7474
LOOP_TYPES = (ast.While, ast.For, ast.AsyncFor)
75+
FUNCTION_TYPES = (ast.FunctionDef, ast.AsyncFunctionDef)
7576
else:
7677
FOR_TYPES = (ast.For,)
7778
LOOP_TYPES = (ast.While, ast.For)
79+
FUNCTION_TYPES = (ast.FunctionDef,)
7880

7981
# https://github.com/python/typed_ast/blob/1.4.0/ast27/Parser/tokenizer.c#L102-L104
8082
TYPE_COMMENT_RE = re.compile(r'^#\s*type:\s*')
@@ -642,7 +644,7 @@ def is_typing_overload_decorator(node):
642644
)
643645

644646
return (
645-
isinstance(value.source, ast.FunctionDef) and
647+
isinstance(value.source, FUNCTION_TYPES) and
646648
any(
647649
is_typing_overload_decorator(dec)
648650
for dec in value.source.decorator_list

pyflakes/test/test_type_annotations.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ def f(s):
5656
return s
5757
""")
5858

59+
@skipIf(version_info < (3, 5), 'new in Python 3.5')
60+
def test_typingOverloadAsync(self):
61+
"""Allow intentional redefinitions via @typing.overload (async)"""
62+
self.flakes("""
63+
from typing import overload
64+
65+
@overload
66+
async def f(s): # type: (None) -> None
67+
pass
68+
69+
@overload
70+
async def f(s): # type: (int) -> int
71+
pass
72+
73+
async def f(s):
74+
return s
75+
""")
76+
5977
def test_overload_with_multiple_decorators(self):
6078
self.flakes("""
6179
from typing import overload

0 commit comments

Comments
 (0)