StructResult 0.8.3__tar.gz → 0.8.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {structresult-0.8.3 → structresult-0.8.4}/PKG-INFO +1 -1
- {structresult-0.8.3 → structresult-0.8.4}/pyproject.toml +1 -1
- {structresult-0.8.3 → structresult-0.8.4}/src/StructResult/result.py +12 -1
- {structresult-0.8.3 → structresult-0.8.4}/src/StructResult.egg-info/PKG-INFO +1 -1
- {structresult-0.8.3 → structresult-0.8.4}/README.md +0 -0
- {structresult-0.8.3 → structresult-0.8.4}/setup.cfg +0 -0
- {structresult-0.8.3 → structresult-0.8.4}/src/StructResult/__init__.py +0 -0
- {structresult-0.8.3 → structresult-0.8.4}/src/StructResult/formatter.py +0 -0
- {structresult-0.8.3 → structresult-0.8.4}/src/StructResult/py.typed +0 -0
- {structresult-0.8.3 → structresult-0.8.4}/src/StructResult.egg-info/SOURCES.txt +0 -0
- {structresult-0.8.3 → structresult-0.8.4}/src/StructResult.egg-info/dependency_links.txt +0 -0
- {structresult-0.8.3 → structresult-0.8.4}/src/StructResult.egg-info/requires.txt +0 -0
- {structresult-0.8.3 → structresult-0.8.4}/src/StructResult.egg-info/top_level.txt +0 -0
- {structresult-0.8.3 → structresult-0.8.4}/test/benchmark.py +0 -0
- {structresult-0.8.3 → structresult-0.8.4}/test/test_formatter.py +0 -0
- {structresult-0.8.3 → structresult-0.8.4}/test/test_result.py +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from dataclasses import dataclass, field
|
|
2
|
-
from typing import Optional, Self, Protocol, Iterator, Any
|
|
2
|
+
from typing import Optional, Self, Protocol, Iterator, Any, Never
|
|
3
3
|
|
|
4
4
|
"""
|
|
5
5
|
Functional error handling system with:
|
|
@@ -19,6 +19,9 @@ class Result(Protocol):
|
|
|
19
19
|
def is_ok(self) -> bool:
|
|
20
20
|
"""Returns True if successful (no errors)"""
|
|
21
21
|
|
|
22
|
+
def unwrap(self) -> Any:
|
|
23
|
+
"""Returns value or raises exception if errors exist"""
|
|
24
|
+
|
|
22
25
|
|
|
23
26
|
class Ok(Result):
|
|
24
27
|
"""Singleton success marker without value"""
|
|
@@ -32,6 +35,10 @@ class Ok(Result):
|
|
|
32
35
|
def value(self) -> "Ok":
|
|
33
36
|
return OK
|
|
34
37
|
|
|
38
|
+
def unwrap(self) -> "Ok":
|
|
39
|
+
"""Always return OK"""
|
|
40
|
+
return OK
|
|
41
|
+
|
|
35
42
|
|
|
36
43
|
OK = Ok()
|
|
37
44
|
|
|
@@ -92,6 +99,10 @@ class Error(ErrorPropagator):
|
|
|
92
99
|
"""
|
|
93
100
|
return Error(err=ExceptionGroup(msg, (self.err,)))
|
|
94
101
|
|
|
102
|
+
def unwrap(self) -> Never:
|
|
103
|
+
"""Always raises exception"""
|
|
104
|
+
raise self.err
|
|
105
|
+
|
|
95
106
|
|
|
96
107
|
@dataclass(slots=True)
|
|
97
108
|
class ErrorAccumulator(ErrorPropagator):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|