diff --git a/mypy/checker.py b/mypy/checker.py index 379da3f1c0da..f2cf27ba8eab 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -1223,11 +1223,11 @@ def check_func_def( if defn.is_async_generator: if not self.is_async_generator_return_type(typ.ret_type): self.fail( - message_registry.INVALID_RETURN_TYPE_FOR_ASYNC_GENERATOR, typ + message_registry.INVALID_RETURN_TYPE_FOR_ASYNC_GENERATOR, defn ) else: if not self.is_generator_return_type(typ.ret_type, defn.is_coroutine): - self.fail(message_registry.INVALID_RETURN_TYPE_FOR_GENERATOR, typ) + self.fail(message_registry.INVALID_RETURN_TYPE_FOR_GENERATOR, defn) # Fix the type if decorated with `@types.coroutine` or `@asyncio.coroutine`. if defn.is_awaitable_coroutine: