Result¶
ExecutionResult
dataclass
¶
Bases: Generic[T, E]
The unified result container for piping runs.
Attributes:
Name | Type | Description |
---|---|---|
result |
Union[Result[T, E], List[Result[T, E]]]
|
Either a Result[T, E] (single pipeline) or List[Result[T, E]] (parallel pipelines). |
trace |
Optional[Union[Trace[T, E], Traces[T, E]]]
|
Optional Trace[T, E] or Traces[T, E] if debug=True. |
execution_time |
float
|
Elapsed time in seconds. |
time_unit |
str
|
Always 's'. |
Source code in neopipe/result.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
|
value()
¶
Extract the inner success value(s). If any entry is Err, raises.
Source code in neopipe/result.py
397 398 399 400 401 402 403 |
|
Result
dataclass
¶
Bases: Generic[T, E]
A Rust-style Result type for monadic error handling in Python.
Source code in neopipe/result.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
Err(error)
staticmethod
¶
Create a Result representing an error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error
|
E
|
The error value. |
required |
Returns:
Type | Description |
---|---|
Self
|
Result[T, E]: An Err variant. |
Source code in neopipe/result.py
37 38 39 40 41 42 43 44 45 46 47 48 |
|
Ok(value)
staticmethod
¶
Create a Result representing a successful value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
T
|
The success value. |
required |
Returns:
Type | Description |
---|---|
Self
|
Result[T, E]: An Ok variant. |
Source code in neopipe/result.py
24 25 26 27 28 29 30 31 32 33 34 35 |
|
__repr__()
¶
Return a string representation of the Result.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Ok(value) or Err(error). |
Source code in neopipe/result.py
313 314 315 316 317 318 319 320 321 |
|
and_then(op)
¶
Chain another Result-returning function if current is Ok.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
op
|
Callable[[T], Result[U, E]]
|
A function that takes a success value and returns a new Result. |
required |
Returns:
Type | Description |
---|---|
Result[U, E]
|
Result[U, E]: The new chained result, or the original error. |
Source code in neopipe/result.py
142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
and_then_async(op)
async
¶
Asynchronously chain another Result-returning function if current is Ok.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
op
|
Callable[[T], Awaitable[Result[U, E]]]
|
An async function that takes a success value and returns a new Result. |
required |
Returns:
Type | Description |
---|---|
Result[U, E]
|
Result[U, E]: The new chained result, or the original error. |
Source code in neopipe/result.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
err()
¶
Get the error value if available.
Returns:
Type | Description |
---|---|
Union[E, None]
|
E | None: The Err value or None. |
Source code in neopipe/result.py
77 78 79 80 81 82 83 84 |
|
err_or(default)
¶
Return the error value or a default.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
default
|
E
|
The fallback error value. |
required |
Returns:
Name | Type | Description |
---|---|---|
E |
E
|
The Err value or the default. |
Source code in neopipe/result.py
224 225 226 227 228 229 230 231 232 233 234 |
|
err_or_else(op)
¶
Return the error value or a value generated from the success value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
op
|
Callable[[T], E]
|
A function that maps the success value to a fallback error. |
required |
Returns:
Name | Type | Description |
---|---|---|
E |
E
|
The Err value or a fallback derived from the success value. |
Source code in neopipe/result.py
236 237 238 239 240 241 242 243 244 245 246 |
|
expect(msg)
¶
Extract the success value or raise with a custom message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg
|
str
|
The message to include in the exception. |
required |
Returns:
Name | Type | Description |
---|---|---|
T |
T
|
The Ok value. |
Raises:
Type | Description |
---|---|
UnwrapError
|
If the result is Err. |
Source code in neopipe/result.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
expect_err(msg)
¶
Extract the error value or raise with a custom message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg
|
str
|
The message to include in the exception. |
required |
Returns:
Name | Type | Description |
---|---|---|
E |
E
|
The Err value. |
Raises:
Type | Description |
---|---|
UnwrapError
|
If the result is Ok. |
Source code in neopipe/result.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
is_err()
¶
Check if the result is Err.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if Err, False otherwise. |
Source code in neopipe/result.py
59 60 61 62 63 64 65 66 |
|
is_ok()
¶
Check if the result is Ok.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if Ok, False otherwise. |
Source code in neopipe/result.py
50 51 52 53 54 55 56 57 |
|
map(op)
¶
Apply a function to the Ok value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
op
|
Callable[[T], U]
|
A function that transforms the success value. |
required |
Returns:
Type | Description |
---|---|
Result[U, E]
|
Result[U, E]: A new Result with transformed success or the original error. |
Source code in neopipe/result.py
86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
map_async(op)
async
¶
Asynchronously apply a function to the Ok value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
op
|
Callable[[T], Awaitable[U]]
|
An async function that transforms the success value. |
required |
Returns:
Type | Description |
---|---|
Result[U, E]
|
Result[U, E]: A new Result with transformed success or the original error. |
Source code in neopipe/result.py
100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
map_err(op)
¶
Apply a function to the Err value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
op
|
Callable[[E], U]
|
A function that transforms the error value. |
required |
Returns:
Type | Description |
---|---|
Result[T, U]
|
Result[T, U]: A new Result with transformed error or the original success. |
Source code in neopipe/result.py
114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
map_err_async(op)
async
¶
Asynchronously apply a function to the Err value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
op
|
Callable[[E], Awaitable[U]]
|
An async function that transforms the error value. |
required |
Returns:
Type | Description |
---|---|
Result[T, U]
|
Result[T, U]: A new Result with transformed error or the original success. |
Source code in neopipe/result.py
128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
match(ok_fn, err_fn)
¶
Pattern match to handle both Ok and Err branches.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ok_fn
|
Callable[[T], U]
|
Function to handle Ok. |
required |
err_fn
|
Callable[[E], U]
|
Function to handle Err. |
required |
Returns:
Name | Type | Description |
---|---|---|
U |
U
|
Result of executing the appropriate handler. |
Source code in neopipe/result.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
ok()
¶
Get the success value if available.
Returns:
Type | Description |
---|---|
Union[T, None]
|
T | None: The Ok value or None. |
Source code in neopipe/result.py
68 69 70 71 72 73 74 75 |
|
to_dict()
¶
Converts the Result to a dictionary.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
The Result as a dictionary |
Source code in neopipe/result.py
297 298 299 300 301 302 303 |
|
to_json()
¶
Converts the Result to a JSON string.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The Result as a JSON string |
Source code in neopipe/result.py
305 306 307 308 309 310 311 |
|
unwrap()
¶
Extract the success value or raise an error.
Returns:
Name | Type | Description |
---|---|---|
T |
T
|
The Ok value. |
Raises:
Type | Description |
---|---|
UnwrapError
|
If the result is Err. |
Source code in neopipe/result.py
172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
unwrap_err()
¶
Extract the error value or raise an error.
Returns:
Name | Type | Description |
---|---|---|
E |
E
|
The Err value. |
Raises:
Type | Description |
---|---|
UnwrapError
|
If the result is Ok. |
Source code in neopipe/result.py
186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
unwrap_or(default)
¶
Return the success value or a default.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
default
|
T
|
The fallback value. |
required |
Returns:
Name | Type | Description |
---|---|---|
T |
T
|
The Ok value or the default. |
Source code in neopipe/result.py
200 201 202 203 204 205 206 207 208 209 210 |
|
unwrap_or_else(op)
¶
Return the success value or a value generated from the error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
op
|
Callable[[E], T]
|
A function that maps the error to a fallback value. |
required |
Returns:
Name | Type | Description |
---|---|---|
T |
T
|
The Ok value or a fallback derived from the error. |
Source code in neopipe/result.py
212 213 214 215 216 217 218 219 220 221 222 |
|
Trace
dataclass
¶
Bases: Generic[T, E]
A sequential trace of one pipeline: steps is a list of (task_name, Result[T, E]).
Source code in neopipe/result.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
|
__getitem__(index)
¶
Get a step by index.
Source code in neopipe/result.py
342 343 344 |
|
__iter__()
¶
Iterate over the steps.
Source code in neopipe/result.py
346 347 348 |
|
Traces
dataclass
¶
Bases: Generic[T, E]
A collection of per-pipeline traces. pipelines is a list of Trace[T, E].
Source code in neopipe/result.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
__getitem__(index)
¶
Get a trace by index.
Source code in neopipe/result.py
365 366 367 |
|
__iter__()
¶
Iterate over the traces.
Source code in neopipe/result.py
369 370 371 |
|
UnwrapError
¶
Bases: Exception
Raised when unwrap is called on an Err value.
Source code in neopipe/result.py
12 13 14 |
|
Err(error)
¶
Creates an Err Result with the given error.
Source code in neopipe/result.py
329 330 331 |
|
Ok(value)
¶
Creates an Ok Result with the given value.
Source code in neopipe/result.py
324 325 326 |
|