Skip to content

Commit

Permalink
Allow non-yielding functions in tornado.gen.coroutine's type hint (t…
Browse files Browse the repository at this point in the history
…ornadoweb#2909)

`@gen.coroutine` deco allows non-yielding functions, so I reflected that in the type hint.

Requires usage of `@typing.overload` due to python/mypy#9435
  • Loading branch information
Jackenmen authored and jeyrce committed Aug 25, 2021
1 parent 5ac3d0c commit 5582e5d
Showing 1 changed file with 13 additions and 1 deletion.
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

0 comments on commit 5582e5d

Please sign in to comment.