Skip to content

Commit 4a7486e

Browse files
committed
Closes #237
1 parent ed314bf commit 4a7486e

File tree

5 files changed

+323
-456
lines changed

5 files changed

+323
-456
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ See (0Ver)[https://0ver.org/].
3232
- Now `Success` and `Failure` (both `io` and pure) return `Any` and not `NoReturn`
3333
- Fixes how `flatten` works, also adds more tests and docs about `Failure` case
3434
- Fixes `Unwrappable` type being parametrized with only one `TypeVar`
35+
- Changes `Success` and `Failure` to return `Any` instead of `NoReturn`
3536

3637
### Misc
3738

3839
- Updates `poetry` version in `travis`
3940
- Imporves ``pipe`` docs with ``lambda`` and `Generic` problem
4041
- Improves docs in several places
4142
- Now examples in docs tries to be docstests where possible
43+
- Changes how tests are checked with `mypy` in CI
4244

4345

4446
## 0.12.0

returns/functions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ def raise_exception(exception: Exception) -> NoReturn:
133133
>>> # Some operation result:
134134
>>> user: Result[int, ValueError] = Failure(ValueError('boom'))
135135
>>> # Here we unwrap internal exception and raise it:
136+
137+
..code::
138+
136139
>>> user.fix(raise_exception)
137140
Traceback (most recent call last):
138141
...

returns/io.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,12 @@ def bind(
308308
309309
>>> from returns.io import IOResult, IOFailure, IOSuccess
310310
>>> def bindable(string: str) -> IOResult[str, str]:
311-
... return IOSuccess(string + 'b')
311+
... if len(string) > 1:
312+
... return IOSuccess(string + 'b')
313+
... return IOFailure(string + 'c')
312314
...
313-
>>> assert IOSuccess('a').bind(bindable) == IOSuccess('ab')
315+
>>> assert IOSuccess('aa').bind(bindable) == IOSuccess('aab')
316+
>>> assert IOSuccess('a').bind(bindable) == IOFailure('ac')
314317
>>> assert IOFailure('a').bind(bindable) == IOFailure('a')
315318
316319
"""
@@ -336,9 +339,12 @@ def bind_result(
336339
>>> from returns.result import Result, Success
337340
338341
>>> def bindable(string: str) -> Result[str, str]:
339-
... return Success(string + 'b')
342+
... if len(string) > 1:
343+
... return Success(string + 'b')
344+
... return Failure(string + 'c')
340345
...
341-
>>> assert IOSuccess('a').bind_result(bindable) == IOSuccess('ab')
346+
>>> assert IOSuccess('aa').bind_result(bindable) == IOSuccess('aab')
347+
>>> assert IOSuccess('a').bind_result(bindable) == IOFailure('ac')
342348
>>> assert IOFailure('a').bind_result(bindable) == IOFailure('a')
343349
344350
"""
@@ -349,7 +355,7 @@ def fix(
349355
function: Callable[[_ErrorType], _NewValueType],
350356
) -> 'IOResult[_NewValueType, _ErrorType]':
351357
"""
352-
Composes a failed container with a pure function to fix the failure.
358+
Composes failed container with a pure function to fix the failure.
353359
354360
.. code:: python
355361
@@ -369,7 +375,7 @@ def rescue(
369375
],
370376
) -> 'IOResult[_ValueType, _NewErrorType]':
371377
"""
372-
Composes a failed container with a function that returns a container.
378+
Composes failed container with a function that returns a container.
373379
374380
.. code:: python
375381
@@ -381,7 +387,6 @@ def rescue(
381387
382388
>>> assert IOFailure('a').rescue(rescuable) == IOFailure('oops')
383389
>>> assert IOFailure('abc').rescue(rescuable) == IOSuccess(3)
384-
385390
>>> assert IOSuccess('a').rescue(rescuable) == IOSuccess('a')
386391
387392
"""
@@ -392,7 +397,7 @@ def alt(
392397
function: Callable[[_ErrorType], _NewErrorType],
393398
) -> 'IOResult[_ValueType, _NewErrorType]':
394399
"""
395-
Composes a failed container with a pure function to modify failure.
400+
Composes failed container with a pure function to modify failure.
396401
397402
.. code:: python
398403
@@ -407,7 +412,7 @@ def value_or(
407412
default_value: _NewValueType,
408413
) -> IO[Union[_ValueType, _NewValueType]]:
409414
"""
410-
Get value or default value.
415+
Get value from succesful container or default value from failed one.
411416
412417
.. code:: python
413418
@@ -420,12 +425,15 @@ def value_or(
420425

421426
def unwrap(self) -> IO[_ValueType]:
422427
"""
423-
Get value or raise exception.
428+
Get value from successful container or raise exception for failed one.
424429
425430
.. code:: python
426431
427432
>>> from returns.io import IO, IOFailure, IOSuccess
428433
>>> assert IOSuccess(1).unwrap() == IO(1)
434+
435+
.. code::
436+
429437
>>> IOFailure(1).unwrap()
430438
Traceback (most recent call last):
431439
...
@@ -436,12 +444,15 @@ def unwrap(self) -> IO[_ValueType]:
436444

437445
def failure(self) -> IO[_ErrorType]:
438446
"""
439-
Get failed value or raise exception.
447+
Get failed value from failed container or raise exception from success.
440448
441449
.. code:: python
442450
443451
>>> from returns.io import IO, IOFailure, IOSuccess
444452
>>> assert IOFailure(1).failure() == IO(1)
453+
454+
.. code::
455+
445456
>>> IOSuccess(1).failure()
446457
Traceback (most recent call last):
447458
...
@@ -471,11 +482,12 @@ def lift(
471482
472483
.. code:: python
473484
474-
>>> from returns.io import IOResult, IOSuccess
485+
>>> from returns.io import IOResult, IOSuccess, IOFailure
475486
>>> def example(argument: int) -> float:
476487
... return argument / 2 # not exactly IO action!
477488
...
478489
>>> assert IOResult.lift(example)(IOSuccess(2)) == IOSuccess(1.0)
490+
>>> assert IOResult.lift(example)(IOFailure(2)) == IOFailure(2)
479491
480492
This one is similar to appling :meth:`~IO.lift`
481493
and :meth:`returns.result.Result.lift` in order.

0 commit comments

Comments
 (0)