Skip to content

Commit 18c0072

Browse files
committed
Merges types and code
1 parent 26636d7 commit 18c0072

File tree

29 files changed

+373
-502
lines changed

29 files changed

+373
-502
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ We follow Semantic Versions since the `0.1.0` release.
2121

2222
### Misc
2323

24+
- Reapplied all types to `.py` files
2425
- Improved docs about `IO` and `Container` concept
2526
- Adds docs about container composition
27+
- Moves from `Alpha` to `Beta`
2628

2729

2830
## 0.7.0

poetry.lock

Lines changed: 1 addition & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ keywords = [
2424
]
2525

2626
classifiers = [
27-
"Development Status :: 3 - Alpha",
27+
"Development Status :: 4 - Beta",
2828
"Intended Audience :: Developers",
2929
"Operating System :: OS Independent",
3030
"Topic :: Software Development :: Libraries :: Python Modules",
@@ -39,7 +39,6 @@ typing-extensions = "^3.7"
3939
mypy = "^0.701"
4040
wemake-python-styleguide = "^0.8.1"
4141
flake8-pytest = "^1.3"
42-
flake8-pyi = "^19.2"
4342

4443
safety = "^1.8"
4544

returns/converters.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
# -*- coding: utf-8 -*-
22

3+
from typing import TypeVar
4+
35
from returns.maybe import Maybe
4-
from returns.result import Failure, Success
6+
from returns.result import Failure, Result, Success
7+
8+
_ValueType = TypeVar('_ValueType')
9+
_ErrorType = TypeVar('_ErrorType')
510

611

7-
def result_to_maybe(result_container):
12+
def result_to_maybe(
13+
result_container: Result[_ValueType, _ErrorType],
14+
) -> Maybe[_ValueType]:
815
"""Converts ``Result`` container to ``Maybe`` container."""
916
return Maybe.new(result_container.value_or(None))
1017

1118

12-
def maybe_to_result(maybe_container):
19+
def maybe_to_result(
20+
maybe_container: Maybe[_ValueType],
21+
) -> Result[_ValueType, None]:
1322
"""Converts ``Maybe`` container to ``Result`` container."""
1423
inner_value = maybe_container.value_or(None)
1524
if inner_value is not None:

returns/converters.pyi

Lines changed: 0 additions & 21 deletions
This file was deleted.

returns/functions.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
# -*- coding: utf-8 -*-
22

3+
from typing import Callable, NoReturn, TypeVar
34

4-
def compose(first, second):
5+
# Just aliases:
6+
_FirstType = TypeVar('_FirstType')
7+
_SecondType = TypeVar('_SecondType')
8+
_ThirdType = TypeVar('_ThirdType')
9+
10+
11+
def compose(
12+
first: Callable[[_FirstType], _SecondType],
13+
second: Callable[[_SecondType], _ThirdType],
14+
) -> Callable[[_FirstType], _ThirdType]:
515
"""
616
Allows function composition.
717
@@ -22,7 +32,7 @@ def compose(first, second):
2232
return lambda argument: second(first(argument))
2333

2434

25-
def raise_exception(exception):
35+
def raise_exception(exception: Exception) -> NoReturn:
2636
"""
2737
Helper function to raise exceptions as a function.
2838

returns/functions.pyi

Lines changed: 0 additions & 19 deletions
This file was deleted.

returns/io.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
from functools import wraps
44
from inspect import iscoroutinefunction
5-
from typing import TypeVar
5+
from typing import Callable, Coroutine, TypeVar, overload
66

7-
from returns.primitives.container import GenericContainerOneSlot
7+
from typing_extensions import final
8+
9+
from returns.primitives.container import Container, GenericContainerOneSlot
810

911
_ValueType = TypeVar('_ValueType')
12+
_NewValueType = TypeVar('_NewValueType')
13+
14+
# Helpers:
15+
_FirstType = TypeVar('_FirstType')
16+
_SecondType = TypeVar('_SecondType')
1017

1118

19+
@final
1220
class IO(GenericContainerOneSlot[_ValueType]):
1321
"""
1422
Explicit marker for impure function results.
@@ -21,7 +29,16 @@ class IO(GenericContainerOneSlot[_ValueType]):
2129
There's no way to directly get its internal value.
2230
"""
2331

24-
def map(self, function): # noqa: A003
32+
_inner_value: _ValueType
33+
34+
def __init__(self, inner_value: _ValueType) -> None:
35+
"""Required for typing."""
36+
Container.__init__(self, inner_value) # type: ignore # noqa: Z462
37+
38+
def map( # noqa: A003
39+
self,
40+
function: Callable[[_ValueType], _NewValueType],
41+
) -> 'IO[_NewValueType]':
2542
"""
2643
Applies function to the inner value.
2744
@@ -32,7 +49,9 @@ def map(self, function): # noqa: A003
3249
"""
3350
return IO(function(self._inner_value))
3451

35-
def bind(self, function):
52+
def bind(
53+
self, function: Callable[[_ValueType], 'IO[_NewValueType]'],
54+
) -> 'IO[_NewValueType]':
3655
"""
3756
Applies 'function' to the result of a previous calculation.
3857
@@ -42,6 +61,23 @@ def bind(self, function):
4261
return function(self._inner_value)
4362

4463

64+
@overload
65+
def impure( # type: ignore
66+
function: Callable[..., Coroutine[_FirstType, _SecondType, _NewValueType]],
67+
) -> Callable[
68+
...,
69+
Coroutine[_FirstType, _SecondType, IO[_NewValueType]],
70+
]:
71+
"""Case for async functions."""
72+
73+
74+
@overload
75+
def impure(
76+
function: Callable[..., _NewValueType],
77+
) -> Callable[..., IO[_NewValueType]]:
78+
"""Case for regular functions."""
79+
80+
4581
def impure(function):
4682
"""
4783
Decorator to mark function that it returns :py:class:`IO` container.

returns/io.pyi

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)