Skip to content

Commit 3014ecc

Browse files
committed
Version 0.7.0 release
1 parent a5d2059 commit 3014ecc

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

CHANGELOG.md

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

55

6-
## WIP
6+
## 0.7.0
77

88
### Features
99

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ class FetchUserProfile(object):
109109
return self._parse_json(response)
110110

111111
@safe
112-
@impure
113112
def _make_request(self, user_id: int) -> requests.Response:
114113
response = requests.get('/api/users/{0}'.format(user_id))
115114
response.raise_for_status()
@@ -148,21 +147,23 @@ that might happen in this particular case:
148147
- `Failure[JsonDecodeException]`
149148

150149
And we can work with each of them precisely.
151-
It is a good practice to create `enum` classes or `Union` types
152-
with all the possible errors.
150+
It is a good practice to create `Enum` classes or `Union` types
151+
with a list of all the possible errors.
153152

154153

155154
## IO marker
156155

157156
But is that all we can improve?
158157
Let's look at `FetchUserProfile` from another angle.
159-
All its methods looks like regular ones:
158+
All its methods look like regular ones:
160159
it is impossible to tell whether they are pure or impure from the first sight.
161160

162161
It leads to a very important consequence:
163162
*we start to mix pure and impure code together*.
163+
We should not do that!
164164

165-
And suffer really bad when testing / reusing it.
165+
When these two concepts are mixed
166+
we suffer really bad when testing or reusing it.
166167
Almost everything should be pure by default.
167168
And we should explicitly mark impure parts of the program.
168169

@@ -194,8 +195,8 @@ class FetchUserProfile(object):
194195

195196
@safe
196197
def _parse_json(
197-
self,
198-
io_response: IO[requests.Response],
198+
self,
199+
io_response: IO[requests.Response],
199200
) -> IO['UserProfile']:
200201
return io_response.map(lambda response: response.json())
201202
```

pyproject.toml

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

returns/io.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@
1010

1111

1212
class IO(GenericContainerOneSlot[_ValueType]):
13-
"""Explicit marker for impure function results."""
13+
"""
14+
Explicit marker for impure function results.
15+
16+
We call it "marker" since once it is marked, it cannot be unmarked.
17+
18+
``IO`` is also a container.
19+
But, it is different in a way
20+
that it cannot be unwrapped / rescued / fixed.
21+
There's no way to directly get its internal value.
22+
"""
1423

1524
def map(self, function): # noqa: A003
1625
"""
@@ -35,7 +44,7 @@ def bind(self, function):
3544

3645
def impure(function):
3746
"""
38-
Decorator to mark function that it returns IO container.
47+
Decorator to mark function that it returns :py:class:`IO` container.
3948
4049
Supports both async and regular functions.
4150
"""

returns/unsafe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
def unsafe_perform_io(wrapped_in_io):
55
"""
6-
Compatibility utility and escape mechanism from IO world.
6+
Compatibility utility and escape mechanism from ``IO`` world.
77
88
Just unwraps the internal value
99
from :py:class:`IO <returns.io.IO>` container.

0 commit comments

Comments
 (0)