Skip to content

Commit 24df71b

Browse files
committed
Working on .pyi types
1 parent 125ded9 commit 24df71b

38 files changed

+423
-387
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
We follow Semantic Versions since the `0.1.0` release.
44

55

6+
## Version 0.4.0
7+
8+
### Features
9+
10+
- Moves all types to `.pyi` files
11+
- Renames all classes according to new naming pattern
12+
13+
614
## Version 0.3.1
715

816
### Bugfixes
@@ -27,7 +35,7 @@ The project is renamed to `returns` and moved to `dry-python` org.
2735
- Adds `Maybe` monad
2836
- Adds immutability and `__slots__` to all monads
2937
- Adds methods to work with failures
30-
- Adds `safe` decorator to convert exceptions to `Either` monad
38+
- Adds `safe` decorator to convert exceptions to `Result` monad
3139
- Adds `is_successful()` function to detect if your result is a success
3240
- Adds `failure()` method to unwrap values from failed monads
3341

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ you will need to get familiar with these concepts:
99

1010
Here are some practical examples of what we are doing here:
1111

12-
- https://medium.com/@rnesytov/using-either-monad-in-python-b6eac698dff5
12+
- https://medium.com/@rnesytov/using-Result-monad-in-python-b6eac698dff5
1313
- https://www.morozov.is/2018/09/08/monad-laws-in-ruby.html
1414

1515

README.md

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![wemake.services](https://img.shields.io/badge/%20-wemake.services-green.svg?label=%20&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC%2FxhBQAAAAFzUkdCAK7OHOkAAAAbUExURQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP%2F%2F%2F5TvxDIAAAAIdFJOUwAjRA8xXANAL%2Bv0SAAAADNJREFUGNNjYCAIOJjRBdBFWMkVQeGzcHAwksJnAPPZGOGAASzPzAEHEGVsLExQwE7YswCb7AFZSF3bbAAAAABJRU5ErkJggg%3D%3D)](https://wemake.services) [![Build Status](https://travis-ci.org/dry-python/returns.svg?branch=master)](https://travis-ci.org/dry-python/returns) [![Coverage Status](https://coveralls.io/repos/github/dry-python/returns/badge.svg?branch=master)](https://coveralls.io/github/dry-python/returns?branch=master) [![Documentation Status](https://readthedocs.org/projects/returns/badge/?version=latest)](https://returns.readthedocs.io/en/latest/?badge=latest) [![Python Version](https://img.shields.io/pypi/pyversions/returns.svg)](https://pypi.org/project/returns/) [![wemake-python-styleguide](https://img.shields.io/badge/style-wemake-000000.svg)](https://github.com/wemake-services/wemake-python-styleguide)
44

55

6-
Make your functions return something meaningful and safe!
6+
Make your functions return something meaningful, typed, and safe!
77

88

99
## Features
@@ -21,27 +21,17 @@ Make your functions return something meaningful and safe!
2121
pip install returns
2222
```
2323

24+
## Why?
2425

25-
## What's inside?
26+
TODO: example with `requests` and `json`
2627

27-
We have several the most iconic monads inside:
2828

29-
- [Result, Failure, and Success](https://returns.readthedocs.io/en/latest/pages/either.html) (also known as `Either`, `Left`, and `Right`)
30-
- [Maybe, Some, and Nothing](https://returns.readthedocs.io/en/latest/pages/maybe.html)
31-
32-
We also care about code readability and developer experience,
33-
so we have included some useful features to make your life easier:
34-
35-
- [Do notation](https://returns.readthedocs.io/en/latest/pages/do-notation.html)
36-
- [Helper functions](https://returns.readthedocs.io/en/latest/pages/functions.html)
37-
38-
39-
## Example
29+
## Pipeline example
4030

4131

4232
```python
4333
from returns.do_notation import do_notation
44-
from returns.either import Result, Success, Failure
34+
from returns.result import Result, Success, Failure
4535

4636
class CreateAccountAndUser(object):
4737
"""Creates new Account-User pair."""
@@ -59,12 +49,3 @@ class CreateAccountAndUser(object):
5949
```
6050

6151
We are [covering what's going on in this example](https://returns.readthedocs.io/en/latest/pages/do-notation.html) in the docs.
62-
63-
64-
## Inspirations
65-
66-
This module is heavily based on:
67-
68-
- [dry-rb/dry-monads](https://github.com/dry-rb/dry-monads)
69-
- [Ø](https://github.com/dbrattli/OSlash)
70-
- [pymonad](https://bitbucket.org/jason_delaat/pymonad)

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def _get_project_meta():
3131

3232
pkg_meta = _get_project_meta()
3333
project = pkg_meta['name']
34-
copyright = '2019, wemake.services' # noqa: A001
34+
copySuccess = '2019, wemake.services' # noqa: A001
3535
author = 'wemake.services'
3636

3737
# The short X.Y version

docs/index.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
.. mdinclude:: ../README.md
22

3+
Inspirations
4+
------------
5+
6+
This module is heavily based on:
7+
8+
- `dry-rb/dry-monads <https://github.com/dry-rb/dry-monads>`_
9+
- `Ø <https://github.com/dbrattli/OSlash>`_
10+
- `pymonad <https://bitbucket.org/jason_delaat/pymonad>`_
11+
312
Contents
413
--------
514

@@ -9,7 +18,7 @@ Contents
918

1019
pages/monad.rst
1120
pages/maybe.rst
12-
pages/either.rst
21+
pages/Result.rst
1322
pages/do-notation.rst
1423
pages/functions.rst
1524

docs/pages/do-notation.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Here's the code to illustrate the task.
2626
.. code:: python
2727
2828
from returns.do_notation import do_notation
29-
from returns.either import Result, Success, Failure
29+
from returns.result import Result, Success, Failure
3030
3131
3232
class CreateAccountAndUser(object):
@@ -138,21 +138,21 @@ Limitations
138138
-----------
139139

140140
There's one limitation in typing
141-
that we are facing right now
141+
that we are facing Success now
142142
due to `mypy issue <https://github.com/python/mypy/issues/3157>`_:
143143

144144
.. code:: python
145145
146146
from returns.do_notation import do_notation
147-
from returns.either import Success
147+
from returns.result import Success
148148
149149
@do_notation
150150
def function(param: int) -> Success[int]:
151151
return Success(param)
152152
153153
reveal_type(function)
154-
# Actual => def (*Any, **Any) -> returns.either.Right*[builtins.int]
155-
# Expected => def (int) -> returns.either.Right*[builtins.int]
154+
# Actual => def (*Any, **Any) -> returns.result.Success*[builtins.int]
155+
# Expected => def (int) -> returns.result.Success*[builtins.int]
156156
157157
This effect can be reduced with the help of `Design by Contract <https://en.wikipedia.org/wiki/Design_by_contract>`_
158158
with these implementations:

docs/pages/either.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Either
1+
Result
22
======
33

44
Also known as ``Result``.
@@ -13,9 +13,9 @@ and ``Failure`` indicates that something has failed.
1313

1414
.. code:: python
1515
16-
from returns.either import Result, Success, Failure
16+
from returns.result import Result, Success, Failure
1717
18-
def find_user(user_id: int) -> Either['User', str]:
18+
def find_user(user_id: int) -> Result['User', str]:
1919
user = User.objects.filter(id=user_id)
2020
if user.exists():
2121
return Success(user[0])
@@ -36,7 +36,7 @@ and other ``None`` exception-friends.
3636
API Reference
3737
-------------
3838

39-
.. autoclasstree:: returns.either
39+
.. autoclasstree:: returns.result
4040

41-
.. automodule:: returns.either
41+
.. automodule:: returns.result
4242
:members:

docs/pages/functions.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ is_successful
99
:func:`is_succesful <returns.functions.is_successful>` is used to
1010
tell whether or not your monad is a success.
1111
We treat only treat monads that does not throw as a successful ones,
12-
basically: :class:`Right <returns.either.Right>`
12+
basically: :class:`Success <returns.result.Success>`
1313
and :class:`Some <returns.maybe.Some>`.
1414

1515
.. code:: python
1616
17-
from returns.either import Success, Failure
17+
from returns.result import Success, Failure
1818
from returns.functions import is_successful
1919
from returns.maybe import Some, Nothing
2020
@@ -29,7 +29,7 @@ safe
2929

3030
:func:`safe <returns.functions.safe>` is used to convert
3131
regular functions that can throw exceptions to functions
32-
that return :class:`Either <returns.either.Either>` monad.
32+
that return :class:`Result <returns.result.Result>` monad.
3333

3434
.. code:: python
3535

docs/pages/monad.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ is used to literally bind two different monads together.
4747

4848
.. code:: python
4949
50-
from returns.either import Either, Success
50+
from returns.result import Result, Success
5151
52-
def make_http_call(user_id: int) -> Either[int, str]:
52+
def make_http_call(user_id: int) -> Result[int, str]:
5353
...
5454
5555
result = Success(1).bind(make_http_call)
56-
# => Will be equal to either Success[int] or Failure[str]
56+
# => Will be equal to Result Success[int] or Failure[str]
5757
5858
So, the rule is: whenever you have some impure functions,
5959
it should return a monad instead.
@@ -63,7 +63,7 @@ to use monads with pure functions.
6363

6464
.. code:: python
6565
66-
from returns.either import Success
66+
from returns.result import Success
6767
6868
def double(state: int) -> int:
6969
return state * 2
@@ -87,7 +87,7 @@ during the pipeline execution:
8787

8888
.. code:: python
8989
90-
from returns.either import Failure
90+
from returns.result import Failure
9191
9292
def double(state: int) -> float:
9393
return state * 2.0
@@ -96,13 +96,13 @@ during the pipeline execution:
9696
# => Will be equal to Success(2.0)
9797
9898
``ebind`` can return any monad you want.
99-
It can also fix your flow and get on the right track again:
99+
It can also fix your flow and get on the Success track again:
100100

101101
.. code:: python
102102
103-
from returns.either import Either, Failure, Success
103+
from returns.result import Result, Failure, Success
104104
105-
def fix(state: Exception) -> Either[int, Exception]:
105+
def fix(state: Exception) -> Result[int, Exception]:
106106
if isinstance(state, ZeroDivisionError):
107107
return Success(0)
108108
return Failure(state)
@@ -123,7 +123,7 @@ inner state of monads into a regular types:
123123

124124
.. code:: python
125125
126-
from returns.either import Failure, Success
126+
from returns.result import Failure, Success
127127
128128
Success(1).value_or(None)
129129
# => 1

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "returns"
33
version = "0.3.1"
4-
description = "Make your functions return something meaningful and safe!"
4+
description = "Make your functions return something meaningful, typed, and safe!"
55
license = "MIT"
66

77
authors = [

0 commit comments

Comments
 (0)