rust-ok 0.2.1__tar.gz → 0.3.0__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.
- {rust_ok-0.2.1 → rust_ok-0.3.0}/PKG-INFO +1 -1
- {rust_ok-0.2.1 → rust_ok-0.3.0}/pyproject.toml +3 -3
- {rust_ok-0.2.1 → rust_ok-0.3.0}/src/rust_ok/err.py +15 -2
- {rust_ok-0.2.1 → rust_ok-0.3.0}/src/rust_ok/ok.py +3 -0
- {rust_ok-0.2.1 → rust_ok-0.3.0}/src/rust_ok/result.py +4 -0
- {rust_ok-0.2.1 → rust_ok-0.3.0}/LICENSE.txt +0 -0
- {rust_ok-0.2.1 → rust_ok-0.3.0}/README.md +0 -0
- {rust_ok-0.2.1 → rust_ok-0.3.0}/src/rust_ok/__init__.py +0 -0
- {rust_ok-0.2.1 → rust_ok-0.3.0}/src/rust_ok/exceptions.py +0 -0
- {rust_ok-0.2.1 → rust_ok-0.3.0}/src/rust_ok/guards.py +0 -0
- {rust_ok-0.2.1 → rust_ok-0.3.0}/src/rust_ok/py.typed +0 -0
- {rust_ok-0.2.1 → rust_ok-0.3.0}/src/rust_ok/trace.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "rust-ok"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.0"
|
|
4
4
|
description = "Rust-inspired Result/Ok/Err primitives for Python"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [
|
|
@@ -37,10 +37,10 @@ build-backend = "uv_build"
|
|
|
37
37
|
dev = [
|
|
38
38
|
"mypy>=1.19.1",
|
|
39
39
|
"pre-commit>=4.5.0,<5.0.0",
|
|
40
|
+
"pytest>=8.3.0,<10.0.0",
|
|
40
41
|
"prek>=0.2.29",
|
|
41
|
-
"pytest>=8.3.0,<9.0.0",
|
|
42
42
|
"pytest-cov>=5.0.0,<6.0.0",
|
|
43
|
-
"ruff>=0.6.8,<0.
|
|
43
|
+
"ruff>=0.6.8,<0.15.0",
|
|
44
44
|
"ty>=0.0.10",
|
|
45
45
|
]
|
|
46
46
|
|
|
@@ -47,7 +47,10 @@ class Err(Result[T_co, E_co]):
|
|
|
47
47
|
return False
|
|
48
48
|
|
|
49
49
|
def unwrap(self) -> T_co:
|
|
50
|
-
|
|
50
|
+
err = UnwrapError(f"Called unwrap on Err: {self._error_value}")
|
|
51
|
+
if isinstance(self._error_value, BaseException):
|
|
52
|
+
raise err from self._error_value
|
|
53
|
+
raise err
|
|
51
54
|
|
|
52
55
|
def unwrap_err(self) -> E_co:
|
|
53
56
|
return self._error_value
|
|
@@ -59,7 +62,10 @@ class Err(Result[T_co, E_co]):
|
|
|
59
62
|
return func(self._error_value)
|
|
60
63
|
|
|
61
64
|
def expect(self, msg: str) -> T_co:
|
|
62
|
-
|
|
65
|
+
err = UnwrapError(f"{msg}: {self._error_value}")
|
|
66
|
+
if isinstance(self._error_value, BaseException):
|
|
67
|
+
raise err from self._error_value
|
|
68
|
+
raise err
|
|
63
69
|
|
|
64
70
|
def is_ok(self) -> bool:
|
|
65
71
|
return False
|
|
@@ -87,6 +93,13 @@ class Err(Result[T_co, E_co]):
|
|
|
87
93
|
def err(self) -> E_co:
|
|
88
94
|
return self._error_value
|
|
89
95
|
|
|
96
|
+
def format_error(self) -> str:
|
|
97
|
+
from .trace import format_exception_chain
|
|
98
|
+
|
|
99
|
+
if isinstance(self._error_value, BaseException):
|
|
100
|
+
return format_exception_chain(self._error_value)
|
|
101
|
+
return str(self._error_value)
|
|
102
|
+
|
|
90
103
|
def unwrap_or_raise(
|
|
91
104
|
self,
|
|
92
105
|
exc_type: type[BaseException] = Exception,
|
|
@@ -79,6 +79,10 @@ class Result(Generic[T_co, E_co]):
|
|
|
79
79
|
"""Return the error value if Err, otherwise None."""
|
|
80
80
|
return self.err()
|
|
81
81
|
|
|
82
|
+
def format_error(self) -> str:
|
|
83
|
+
"""Return a formatted string of the error, including traceback if available."""
|
|
84
|
+
raise NotImplementedError # pragma: no cover
|
|
85
|
+
|
|
82
86
|
def unwrap_or_raise(
|
|
83
87
|
self,
|
|
84
88
|
exc_type: type[BaseException] = Exception,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|