MCPcopy Index your code
hub / github.com/dry-python/returns / is_successful

Function is_successful

returns/pipeline.py:11–38  ·  view source on GitHub ↗

Determines if a container was successful or not. .. code:: python >>> from returns.maybe import Some, Nothing >>> from returns.result import Failure, Success >>> from returns.io import IOSuccess, IOFailure >>> assert is_successful(Some(1)) >>> assert not is_

(container: Unwrappable[Any, Any])

Source from the content-addressed store, hash-verified

9
10# TODO: add overloads for specific types, so it can narrow them with `TypeIs`
11def is_successful(container: Unwrappable[Any, Any]) -> bool:
12 """
13 Determines if a container was successful or not.
14
15 .. code:: python
16
17 >>> from returns.maybe import Some, Nothing
18 >>> from returns.result import Failure, Success
19 >>> from returns.io import IOSuccess, IOFailure
20
21 >>> assert is_successful(Some(1))
22 >>> assert not is_successful(Nothing)
23
24 >>> assert is_successful(Success(1))
25 >>> assert not is_successful(Failure(1))
26
27 >>> assert is_successful(IOSuccess(1))
28 >>> assert not is_successful(IOFailure(1))
29
30 This function can work with containers
31 that are instance of :class:`returns.interfaces.unwrappable.Unwrappable`.
32
33 """
34 try:
35 container.unwrap()
36 except UnwrapFailedError:
37 return False
38 return True

Callers 7

result_to_maybeFunction · 0.90
maybe_to_resultFunction · 0.90
unwrap_or_failureFunction · 0.90
test_is_successfulFunction · 0.90
test_ioresulteFunction · 0.90

Calls 1

unwrapMethod · 0.45

Tested by 4

test_is_successfulFunction · 0.72
test_ioresulteFunction · 0.72