Skip to content
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

Allow non-yielding functions in tornado.gen.coroutine's type hint #2909

Merged
merged 4 commits into from
Sep 13, 2020
Merged
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
14 changes: 13 additions & 1 deletion tornado/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get(self):
from tornado.util import TimeoutError

import typing
from typing import Union, Any, Callable, List, Type, Tuple, Awaitable, Dict
from typing import Union, Any, Callable, List, Type, Tuple, Awaitable, Dict, overload

if typing.TYPE_CHECKING:
from typing import Sequence, Deque, Optional, Set, Iterable # noqa: F401
Expand Down Expand Up @@ -153,8 +153,20 @@ def _create_future() -> Future:
return future


@overload
def coroutine(
func: Callable[..., "Generator[Any, Any, _T]"]
) -> Callable[..., "Future[_T]"]:
...


@overload
def coroutine(func: Callable[..., _T]) -> Callable[..., "Future[_T]"]:
...


def coroutine(
func: Union[Callable[..., "Generator[Any, Any, _T]"], Callable[..., _T]]
) -> Callable[..., "Future[_T]"]:
"""Decorator for asynchronous generators.

Expand Down