MCPcopy
hub / github.com/tornadoweb/tornado / convert_yielded

Function convert_yielded

tornado/gen.py:872–900  ·  view source on GitHub ↗

Convert a yielded object into a `.Future`. The default implementation accepts lists, dictionaries, and Futures. This has the side effect of starting any coroutines that did not start themselves, similar to `asyncio.ensure_future`. If the `~functools.singledispatch` library is avail

(yielded: _Yieldable)

Source from the content-addressed store, hash-verified

870
871
872def convert_yielded(yielded: _Yieldable) -> Future:
873 """Convert a yielded object into a `.Future`.
874
875 The default implementation accepts lists, dictionaries, and
876 Futures. This has the side effect of starting any coroutines that
877 did not start themselves, similar to `asyncio.ensure_future`.
878
879 If the `~functools.singledispatch` library is available, this function
880 may be extended to support additional types. For example::
881
882 @convert_yielded.register(asyncio.Future)
883 def _(asyncio_future):
884 return tornado.platform.asyncio.to_tornado_future(asyncio_future)
885
886 .. versionadded:: 4.1
887
888 """
889 if yielded is None or yielded is moment:
890 return moment
891 elif yielded is _null_future:
892 return _null_future
893 elif isinstance(yielded, (list, dict)):
894 return multi(yielded) # type: ignore
895 elif is_future(yielded):
896 return typing.cast(Future, yielded)
897 elif isawaitable(yielded):
898 return _wrap_awaitable(yielded) # type: ignore
899 else:
900 raise BadYieldError(f"yielded unknown object {yielded!r}")
901
902
903convert_yielded = singledispatch(convert_yielded)

Callers 4

runMethod · 0.90
to_asyncio_futureFunction · 0.90
with_timeoutFunction · 0.85
handle_yieldMethod · 0.85

Calls 4

is_futureFunction · 0.90
multiFunction · 0.85
_wrap_awaitableFunction · 0.85
BadYieldErrorClass · 0.85

Tested by

no test coverage detected