File tree 3 files changed +19
-8
lines changed
3 files changed +19
-8
lines changed Original file line number Diff line number Diff line change 1
1
# Migration guides
2
2
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
+
3
11
## 0.10 -> 0.11 migration
4
12
5
13
The 0.11 migration includes one breaking change:
Original file line number Diff line number Diff line change @@ -75,11 +75,14 @@ To something like this:
75
75
76
76
user_result = get_user_by_email(email)
77
77
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 )
80
80
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 ``.
83
86
84
87
And if you're using python version ``3.10 `` or later, you can use the elegant ``match `` statement as well:
85
88
@@ -186,9 +189,9 @@ Access the value directly, without any other checks:
186
189
187
190
>>> res1 = Ok(' yay' )
188
191
>>> res2 = Err(' nay' )
189
- >>> res1.value
192
+ >>> res1.ok_value
190
193
'yay'
191
- >>> res2.value
194
+ >>> res2.err_value
192
195
'nay'
193
196
194
197
Note that this is a property, you cannot assign to it. Results are immutable.
@@ -341,7 +344,7 @@ unconventional syntax (without the usual ``@``):
341
344
342
345
res = safe_do_something(...) # Ok(...) or Err(...)
343
346
if isinstance(res, Ok):
344
- print(res.value )
347
+ print(res.ok_value )
345
348
346
349
347
350
Do notation
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ def value(self) -> T:
88
88
"""
89
89
warn (
90
90
"Accessing `.value` on Result type is deprecated, please use "
91
- + "`.ok_value` or ' .err_value' instead" ,
91
+ + "`.ok_value` or ` .err_value` instead" ,
92
92
DeprecationWarning ,
93
93
stacklevel = 2 ,
94
94
)
You can’t perform that action at this time.
0 commit comments