Skip to content

Commit d25e225

Browse files
authored
Allow non-yielding functions in tornado.gen.coroutine's type hint (#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
1 parent 0a7463e commit d25e225

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tornado/gen.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def get(self):
9191
from tornado.util import TimeoutError
9292

9393
import typing
94-
from typing import Union, Any, Callable, List, Type, Tuple, Awaitable, Dict
94+
from typing import Union, Any, Callable, List, Type, Tuple, Awaitable, Dict, overload
9595

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

155155

156+
@overload
156157
def coroutine(
157158
func: Callable[..., "Generator[Any, Any, _T]"]
159+
) -> Callable[..., "Future[_T]"]:
160+
...
161+
162+
163+
@overload
164+
def coroutine(func: Callable[..., _T]) -> Callable[..., "Future[_T]"]:
165+
...
166+
167+
168+
def coroutine(
169+
func: Union[Callable[..., "Generator[Any, Any, _T]"], Callable[..., _T]]
158170
) -> Callable[..., "Future[_T]"]:
159171
"""Decorator for asynchronous generators.
160172

0 commit comments

Comments
 (0)