Skip to content

Commit d77f3f6

Browse files
authored
Update docs for deprecated .value field (#159)
1 parent 3994af7 commit d77f3f6

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

MIGRATING.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Migration guides
22

3+
## 0.11.0 -> 0.12 migration
4+
5+
``.value`` is now deprecated. New code should use ``.ok_value`` on instances of
6+
``Ok`` and ``.err_value`` on instances of ``Err``. Existing code using
7+
``.value`` will continue to work, but will result in a deprecation warning being
8+
logged. Users of this library are encouraged to migrate away from ``.value``
9+
before it is removed in a future version.
10+
311
## 0.10 -> 0.11 migration
412

513
The 0.11 migration includes one breaking change:

README.rst

+10-7
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,14 @@ To something like this:
7575

7676
user_result = get_user_by_email(email)
7777
if isinstance(user_result, Ok): # or `is_ok(user_result)`
78-
# type(user_result.value) == User
79-
do_something(user_result.value)
78+
# type(user_result.ok_value) == User
79+
do_something(user_result.ok_value)
8080
else: # or `elif is_err(user_result)`
81-
# type(user_result.value) == str
82-
raise RuntimeError('Could not fetch user: %s' % user_result.value)
81+
# type(user_result.err_value) == str
82+
raise RuntimeError('Could not fetch user: %s' % user_result.err_value)
83+
84+
Note that ``.ok_value`` exists only on an instance of ``Ok`` and ``.err_value``
85+
exists only on an instance of ``Err``.
8386

8487
And if you're using python version ``3.10`` or later, you can use the elegant ``match`` statement as well:
8588

@@ -186,9 +189,9 @@ Access the value directly, without any other checks:
186189

187190
>>> res1 = Ok('yay')
188191
>>> res2 = Err('nay')
189-
>>> res1.value
192+
>>> res1.ok_value
190193
'yay'
191-
>>> res2.value
194+
>>> res2.err_value
192195
'nay'
193196

194197
Note that this is a property, you cannot assign to it. Results are immutable.
@@ -341,7 +344,7 @@ unconventional syntax (without the usual ``@``):
341344

342345
res = safe_do_something(...) # Ok(...) or Err(...)
343346
if isinstance(res, Ok):
344-
print(res.value)
347+
print(res.ok_value)
345348

346349

347350
Do notation

src/result/result.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def value(self) -> T:
8888
"""
8989
warn(
9090
"Accessing `.value` on Result type is deprecated, please use "
91-
+ "`.ok_value` or '.err_value' instead",
91+
+ "`.ok_value` or `.err_value` instead",
9292
DeprecationWarning,
9393
stacklevel=2,
9494
)

0 commit comments

Comments
 (0)