Skip to content

Commit c7e42f4

Browse files
committed
Improves types
1 parent cab7811 commit c7e42f4

File tree

5 files changed

+10
-11
lines changed

5 files changed

+10
-11
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ install:
1818

1919
script:
2020
- poetry run flake8 dry_monads tests docs
21-
- poetry run mypy dry_monads
21+
- poetry run mypy dry_monads tests/**/*.py
2222
- poetry run pytest
2323
# TODO: add docs and enable
2424
# - poetry run doc8 -q docs

dry_monads/either.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ def bind(self, function) -> 'Left[ValueType]':
3232
"""Returns the 'Left' instance that was used to call the method."""
3333
return Left(self._inner_value)
3434

35-
def value_or(
36-
self,
37-
default_value: NewValueType,
38-
) -> NewValueType:
35+
def value_or(self, default_value: NewValueType) -> NewValueType:
3936
"""Returns the value if we deal with 'Right' or default if 'Left'."""
4037
return default_value
4138

@@ -73,10 +70,7 @@ def bind(
7370
"""
7471
return function(self._inner_value)
7572

76-
def value_or(
77-
self,
78-
default_value: NewValueType,
79-
) -> ValueType:
73+
def value_or(self, default_value: NewValueType) -> ValueType:
8074
"""Returns the value if we deal with 'Right' or default if 'Left'."""
8175
return self._inner_value
8276

dry_monads/primitives/monad.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ def bind(self, function): # pragma: no cover
4747
"""
4848
raise NotImplementedError
4949

50+
@abstractmethod
51+
def value_of(self, default_value):
52+
"""Forces to unwrap value from monad or return a default."""
53+
raise NotImplementedError
54+
5055
def __str__(self) -> str:
5156
"""Converts to string."""
5257
return '{0}: {1}'.format(

tests/test_either/test_bind.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def factory(inner_value: int) -> Right[int]:
1818
def test_left_identity_failure():
1919
"""Ensures that left identity works for Right monad."""
2020
def factory(inner_value: int) -> Left[TypeError]:
21-
return Left(TypeError)
21+
return Left(TypeError())
2222

2323
input_value = 5
2424
bound = Left(input_value).bind(factory)

tests/test_primitives/test_monad.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
def test_abstract_class():
99
"""Ensures that Monad can not be instanciated."""
1010
with pytest.raises(TypeError):
11-
Monad()
11+
Monad(1) # type: ignore

0 commit comments

Comments
 (0)