def from_future(
        cls,
        inner_value: Future[_NewValueType],
    ) -> 'RequiresContextFutureResult[_NewValueType, Any, NoDeps]':
        """
        Creates new container with successful ``Future`` as a unit value.

        .. code:: python

          >>> import anyio
          >>> from returns.context import RequiresContextFutureResult
          >>> from returns.future import Future
          >>> from returns.io import IOSuccess

          >>> assert anyio.run(
          ...    RequiresContextFutureResult.from_future(Future.from_value(1)),
          ...    RequiresContextFutureResult.empty,
          ... ) == IOSuccess(1)

        """
        return RequiresContextFutureResult(
            lambda _: FutureResult.from_future(inner_value), )
Ejemplo n.º 2
0
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