Skip to content

Commit 7f6d859

Browse files
committed
Broken: debuging mypy
1 parent 7639d33 commit 7f6d859

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

returns/io.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,26 @@
44
from functools import wraps
55
from inspect import iscoroutinefunction
66
from typing import (
7-
Any,
87
Callable,
9-
Coroutine,
108
ClassVar,
11-
Type,
9+
Coroutine,
1210
Generic,
1311
NoReturn,
12+
Type,
1413
TypeVar,
1514
Union,
1615
overload,
1716
)
1817

1918
from typing_extensions import final
2019

21-
from returns.primitives.exceptions import UnwrapFailedError
2220
from returns._generated.squash import _squash as io_squash # noqa: F401
23-
from returns.pipeline import is_successful
2421
from returns.primitives.container import BaseContainer
2522
from returns.result import Failure, Result, Success
2623

2724
_ValueType = TypeVar('_ValueType', covariant=True)
2825
_NewValueType = TypeVar('_NewValueType')
2926

30-
_T = TypeVar('_T', contravariant=True)
31-
3227
# Result related:
3328
_ErrorType = TypeVar('_ErrorType', covariant=True)
3429
_NewErrorType = TypeVar('_NewErrorType')
@@ -575,11 +570,26 @@ def from_successful_io(
575570
def from_result(
576571
cls, container: Result[_NewValueType, _NewErrorType],
577572
) -> 'IOResult[_NewValueType, _NewErrorType]':
578-
""""""
573+
"""
574+
Creates ``IOResult`` from ``Result`` value.
575+
576+
.. code:: python
577+
578+
>>> from returns.io import IOResult, IOSuccess, IOFailure
579+
>>> from returns.result import Success, Failure
580+
581+
>>> assert IOResult.from_result(Success(1)) == IOSuccess(1)
582+
>>> assert IOResult.from_result(Failure(2)) == IOFailure(2)
583+
584+
"""
579585
if isinstance(container, container.success_type):
580586
return _IOSuccess(container)
581587
return _IOFailure(container)
582588

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

584594
@final
585595
class _IOFailure(IOResult):

returns/pipeline.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
# -*- coding: utf-8 -*-
22

3-
from typing import TYPE_CHECKING, Union
3+
from typing import Union
44

55
from returns._generated.pipe import _pipe as pipe # noqa: F401
66
from returns._generated.pipeline import _pipeline as pipeline # noqa: F401
7+
from returns.io import IOResult
8+
from returns.maybe import Maybe
79
from returns.primitives.exceptions import UnwrapFailedError
10+
from returns.result import Result
811

9-
if TYPE_CHECKING: # pragma: no cover
10-
from returns.maybe import Maybe # noqa: WPS433
11-
from returns.result import Result # noqa: WPS433
12-
from returns.io import IOResult # noqa: WPS433
13-
14-
# Logical aliases:
15-
_Unwrapable = Union[Result, Maybe, IOResult]
12+
# Logical aliases:
13+
_Unwrapable = Union[Result, Maybe, IOResult]
1614

1715

1816
def is_successful(container: '_Unwrapable') -> bool:

tests/test_io/test_ioresult_container/test_ioresult_bind.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def factory(inner_value: int) -> IOResult[int, str]:
1616

1717
assert bound.bind(factory) == factory(input_value)
1818
assert IOSuccess(input_value).bind(factory) == factory(input_value)
19+
assert IOSuccess('a').bind(factory) == factory('a')
1920
assert str(bound.bind(factory)) == '<IOResult: <Success: 10>>'
2021

2122
input_value = 0

0 commit comments

Comments
 (0)