Skip to content

Fix crash when checking async generator return type #5123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,9 +929,13 @@ def is_unannotated_any(t: Type) -> bool:
ret_type = fdef.type.ret_type
if is_unannotated_any(ret_type):
self.fail(messages.RETURN_TYPE_EXPECTED, fdef)
elif (fdef.is_coroutine and isinstance(ret_type, Instance) and
is_unannotated_any(self.get_coroutine_return_type(ret_type))):
self.fail(messages.RETURN_TYPE_EXPECTED, fdef)
elif fdef.is_generator:
if is_unannotated_any(self.get_generator_return_type(ret_type,
fdef.is_coroutine)):
self.fail(messages.RETURN_TYPE_EXPECTED, fdef)
elif fdef.is_coroutine and isinstance(ret_type, Instance):
if is_unannotated_any(self.get_coroutine_return_type(ret_type)):
self.fail(messages.RETURN_TYPE_EXPECTED, fdef)
if any(is_unannotated_any(t) for t in fdef.type.arg_types):
self.fail(messages.ARGUMENT_TYPE_EXPECTED, fdef)

Expand Down
30 changes: 30 additions & 0 deletions test-data/unit/check-async-await.test
Original file line number Diff line number Diff line change
Expand Up @@ -669,3 +669,33 @@ async def decorated_host_coroutine() -> None:
[builtins fixtures/async_await.pyi]
[typing fixtures/typing-full.pyi]
[out]

[case testAsyncGenDisallowUntyped]
# flags: --disallow-untyped-defs
# These should not crash
from typing import AsyncGenerator, Any

async def f() -> AsyncGenerator[int, None]:
yield 0

async def g() -> AsyncGenerator[Any, None]:
yield 0
[builtins fixtures/async_await.pyi]
[typing fixtures/typing-full.pyi]
[out]

[case testAsyncGenDisallowUntypedTriggers]
# flags: --disallow-untyped-defs
from typing import AsyncGenerator, Any

async def f() -> AsyncGenerator[Any, Any]:
yield None

async def h() -> Any:
yield 0

async def g(): # E: Function is missing a type annotation
yield 0
[builtins fixtures/async_await.pyi]
[typing fixtures/typing-full.pyi]
[out]