File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,28 @@ If you want to `safe` handle only a set of exceptions:
116
116
...
117
117
ValueError : Too big
118
118
119
+ attempt
120
+ ~~~~~~~
121
+
122
+ Similar to :func: `safe <returns.result.safe> ` function but instead
123
+ of wrapping the exception error in a Failure container it'll wrap the
124
+ argument that lead to that exception.
125
+
126
+ .. code :: python
127
+
128
+ >> > from returns.result import Failure, Success, attempt
129
+
130
+ >> > @ attempt
131
+ ... def divide_itself (number : int ) -> float :
132
+ ... return number / number
133
+
134
+ >> > assert divide_itself(2 ) == Success(1.0 )
135
+ >> > assert divide_itself(0 ) == Failure(0 )
136
+
137
+ .. warning ::
138
+
139
+ This decorator works only with functions that has just one argument.
140
+
119
141
FAQ
120
142
---
121
143
You can’t perform that action at this time.
0 commit comments