def from_io( cls, inner_value: IO[_NewValueType], ) -> 'RequiresContextFutureResult[_NewValueType, Any, NoDeps]': """ Creates new container from successful ``IO`` value. .. code:: python >>> import anyio >>> from returns.io import IO, IOSuccess >>> from returns.context import RequiresContextFutureResult >>> assert anyio.run( ... RequiresContextFutureResult.from_io(IO(1)), ... RequiresContextFutureResult.empty, ... ) == IOSuccess(1) """ return RequiresContextFutureResult( lambda deps: FutureResult.from_io(inner_value), )
async def test_inner_value(subtests): """Ensure that coroutine correct value is preserved for all units.""" containers = [ # We have to define these values inside the test, because # otherwise `anyio` will `await` reused coroutines. # And they have to be fresh. That's why we use subtests for it. FutureResult.from_value(1), FutureResult.from_failure(1), FutureResult.from_io(IO(1)), FutureResult.from_failed_io(IO(1)), FutureResult.from_ioresult(IOSuccess(1)), FutureResult.from_ioresult(IOFailure(1)), FutureResult.from_result(Success(1)), FutureResult.from_result(Failure(1)), FutureResult.from_future(Future.from_value(1)), FutureResult.from_failed_future(Future.from_value(1)), FutureResult.from_typecast(Future.from_value(Success(1))), ] for container in containers: with subtests.test(container=container): result_inst = await container assert result_inst._inner_value._inner_value == 1 # noqa: WPS437