def _get_coroutine_or_flag_problem(async_fn: Callable[..., Awaitable[Any]], *args: Any, **kwargs: Any) -> Awaitable[Any]: """Call async_fn(*args) to produce and return a coroutine. If that doesn't work or doesn't produce a coroutine, try to get help from trio in describing what went wrong. """ try: # can we call it? coro = async_fn(*args, **kwargs) except TypeError: probe_fn = async_fn else: # did we get a coroutine object back? if isinstance(coro, collections.abc.Coroutine): return coro probe_fn = partial(async_fn, **kwargs) # TODO: upstream a change that lets us access just the nice # error detection logic without running the risk of starting a task # If we're not happy with this async_fn, trio won't be either, # and will tell us why in much greater detail. try: trio.hazmat.spawn_system_task(probe_fn, *args) except TypeError as ex: problem_with_async_fn = ex else: # we started the task successfully, wtf? raise trio.TrioInternalError( "tried to spawn a dummy task to figure out what was wrong with " "{async_fn!r} as an async function, but it seems to have started " "successfully -- all bets are off at this point") raise problem_with_async_fn
def fget(self): if self.crashed and not self._error_list: self._error_list.append(trio.TrioInternalError("See pytest-trio issue #75")) return self._error_list