Skip to content

Commit ac48bb0

Browse files
committed
Fixes #202
1 parent 066d1f4 commit ac48bb0

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ incremental in minor, bugfixes only are patches.
66
See (0Ver)[https://0ver.org/].
77

88

9+
## 0.13.0
10+
11+
### Bugfixes
12+
13+
- Fixes that containers were not usable with `multiprocessing`
14+
15+
916
## 0.12.0
1017

1118
### Features

returns/functions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Any, Callable, NoReturn, TypeVar
44

55
from returns.generated.box import _box as box # noqa: F401, WPS436
6+
from returns.generated.io_context import _context as io_context
67

78
# Aliases:
89
_FirstType = TypeVar('_FirstType')
@@ -72,7 +73,8 @@ def tap(
7273
"""
7374
Allows to apply some function and return an argument, instead of a result.
7475
75-
Is usefull for side-effects like ``print()``, ``logger.log``, etc.
76+
Is usefull for composing functions with
77+
side-effects like ``print()``, ``logger.log()``, etc.
7678
7779
.. code:: python
7880

returns/io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def lift(
8686
"""
8787
Lifts function to be wrapped in ``IO`` for better composition.
8888
89-
In other words, it modifies the function
89+
In other words, it modifies the function's
9090
signature from: ``a -> b`` to: ``IO[a] -> IO[b]``
9191
9292
This is how it should be used:

returns/primitives/container.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self, inner_value) -> None:
2727
"""
2828
object.__setattr__(self, '_inner_value', inner_value) # noqa: WPS609
2929

30-
def __setattr__(self, attr_name: str, attr_value) -> NoReturn:
30+
def __setattr__(self, attr_name: str, attr_value: Any) -> NoReturn:
3131
"""Makes inner state of the containers immutable."""
3232
raise ImmutableStateError()
3333

@@ -42,7 +42,7 @@ def __str__(self) -> str:
4242
str(self._inner_value),
4343
)
4444

45-
def __eq__(self, other) -> bool:
45+
def __eq__(self, other: Any) -> bool:
4646
"""Used to compare two 'Container' objects."""
4747
if not isinstance(self, type(other)):
4848
return False
@@ -52,6 +52,14 @@ def __hash__(self) -> int:
5252
"""Used to use this value as a key."""
5353
return hash(self._inner_value)
5454

55+
def __getstate__(self) -> Any:
56+
"""That's how this object will be pickled."""
57+
return self._inner_value
58+
59+
def __setstate__(self, state: Any) -> None:
60+
"""Loading state from pickled data."""
61+
object.__setattr__(self, '_inner_value', state) # noqa: WPS609
62+
5563

5664
@runtime
5765
class Bindable(Protocol[_ValueType]):

tests/test_io/test_io_pickle.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from returns.io import IO
4+
5+
6+
def test_io_pickle():
7+
"""Tests how pickle protocol works for containers."""
8+
assert IO(1).__getstate__() == 1
9+
10+
11+
def test_io_pickle_restore():
12+
"""Ensures that object can be restored."""
13+
container = IO(2)
14+
container.__setstate__(1)
15+
assert container == IO(1)

0 commit comments

Comments
 (0)