Skip to content

Commit 579e1d1

Browse files
committed
Stabilizes build
1 parent e626ed8 commit 579e1d1

File tree

7 files changed

+30
-9
lines changed

7 files changed

+30
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,4 @@ fabric.properties
199199
### Custom ###
200200
ex.py
201201
.vscode/tags
202+
.pyre

docs/pages/io.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,21 @@ If the value is fetched, input, received, selected, than use ``IO`` container.
338338

339339
Most web applications are just covered with ``IO``.
340340

341+
How to create unit object for IOResult?
342+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
343+
344+
*TLDR*: you need to explicitly annotate values like so:
345+
346+
.. code:: python
347+
348+
>>> from returns.io import IOResult, IOSuccess, IOFailure
349+
>>> first: IOResult[int, str] = IOSuccess(1)
350+
>>> second: IOResult[float, int] = IOFailure(1)
351+
352+
Otherwise, ``mypy`` won't be able to typecheck your code.
353+
354+
See :ref:`result-units` for more details.
355+
341356
Why IO should be at the top level of composition?
342357
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
343358

docs/pages/result.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ This happens due to `mypy issue <https://github.com/python/mypy/issues/3157>`_.
9090
FAQ
9191
---
9292

93+
.. _result-units:
94+
9395
How to create unit objects?
9496
~~~~~~~~~~~~~~~~~~~~~~~~~~~
9597

returns/io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def from_result(
588588

589589
def __str__(self) -> str:
590590
"""Custom ``str`` representation for better readability."""
591-
return '<IOResult: {0}'.format(self._inner_value)
591+
return '<IOResult: {0}>'.format(self._inner_value)
592592

593593

594594
@final
@@ -691,7 +691,7 @@ def IOFailure( # noqa: N802
691691
692692
>>> from returns.io import IOFailure
693693
>>> str(IOFailure(1))
694-
'<IOResult: <Failure: 1>>'§
694+
'<IOResult: <Failure: 1>>'
695695
696696
"""
697697
return _IOFailure(Failure(inner_value))

returns/result.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def failure(self):
335335

336336

337337
@final
338-
class _Success(Result[_ValueType, Any]):
338+
class _Success(Result[_ValueType, _ErrorType]):
339339
"""
340340
Represents a calculation which has succeeded and contains the result.
341341

tests/test_io/test_ioresult_container/test_ioresult_bind.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ def factory(inner_value: int) -> IOResult[int, str]:
1515
bound: IOResult[int, str] = IOSuccess(input_value)
1616

1717
assert bound.bind(factory) == factory(input_value)
18-
assert IOSuccess(input_value).bind(factory) == factory(input_value)
19-
assert IOSuccess('a').bind(factory) == factory('a')
2018
assert str(bound.bind(factory)) == '<IOResult: <Success: 10>>'
2119

2220
input_value = 0
@@ -55,9 +53,13 @@ def factory(inner_value: int) -> Result[int, str]:
5553
return Success(inner_value + 1)
5654
return Failure('nope')
5755

58-
assert IOSuccess(1).bind_result(factory) == IOSuccess(2)
59-
assert IOSuccess(0).bind_result(factory) == IOFailure('nope')
60-
assert IOFailure('a').bind_result(factory) == IOFailure('a')
56+
first: IOResult[int, str] = IOSuccess(1)
57+
second: IOResult[int, str] = IOSuccess(0)
58+
third: IOResult[int, str] = IOFailure('a')
59+
60+
assert first.bind_result(factory) == IOSuccess(2)
61+
assert second.bind_result(factory) == IOFailure('nope')
62+
assert third.bind_result(factory) == IOFailure('a')
6163

6264

6365
def test_rescue_success():

tests/test_result/test_result_bind.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def factory(inner_value: int) -> Result[int, str]:
1414
bound: Result[int, str] = Success(input_value)
1515

1616
assert bound.bind(factory) == factory(input_value)
17-
assert Success(input_value) == factory(input_value)
1817
assert str(bound.bind(factory)) == '<Success: 10>'
1918

2019
input_value = 0
@@ -55,6 +54,7 @@ def factory(inner_value: int) -> Result[int, int]:
5554
bound: Result[int, int] = Failure(input_value)
5655

5756
assert bound.bind(factory) == Failure(input_value)
57+
assert Failure(input_value).bind(factory) == Failure(5)
5858
assert bound.unify(factory) == Failure(input_value)
5959
assert str(bound) == '<Failure: 5>'
6060

@@ -67,6 +67,7 @@ def factory(inner_value) -> Result[int, str]:
6767
bound = Success(5).rescue(factory)
6868

6969
assert bound == Success(5)
70+
assert Success(5).rescue(factory) == Success(5)
7071
assert str(bound) == '<Success: 5>'
7172

7273

0 commit comments

Comments
 (0)