rust-ok 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl
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/__init__.py +7 -2
- rust_ok/err.py +11 -4
- rust_ok/ok.py +10 -6
- rust_ok/result.py +3 -2
- rust_ok/trace.py +1 -1
- {rust_ok-0.1.0.dist-info → rust_ok-0.2.0.dist-info}/METADATA +2 -2
- rust_ok-0.2.0.dist-info/RECORD +11 -0
- {rust_ok-0.1.0.dist-info → rust_ok-0.2.0.dist-info}/WHEEL +1 -1
- rust_ok-0.1.0.dist-info/RECORD +0 -11
rust_ok/__init__.py
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"""Public API for rust-ok."""
|
|
2
2
|
|
|
3
|
-
from .
|
|
3
|
+
from importlib.metadata import version
|
|
4
|
+
|
|
5
|
+
__version__ = version("rust_ok")
|
|
6
|
+
|
|
4
7
|
from .err import Err
|
|
5
|
-
from .
|
|
8
|
+
from .exceptions import IsNotError, RustOkError, UnwrapError
|
|
6
9
|
from .guards import is_err, is_ok
|
|
10
|
+
from .ok import Ok
|
|
7
11
|
from .result import Result
|
|
8
12
|
from .trace import format_exception_chain, iter_causes
|
|
9
13
|
|
|
@@ -18,4 +22,5 @@ __all__ = [
|
|
|
18
22
|
"iter_causes",
|
|
19
23
|
"is_err",
|
|
20
24
|
"is_ok",
|
|
25
|
+
"__version__",
|
|
21
26
|
]
|
rust_ok/err.py
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from typing import Any, TypeVar, cast, overload
|
|
6
7
|
|
|
7
8
|
from .exceptions import UnwrapError
|
|
8
9
|
from .result import Result
|
|
@@ -19,8 +20,14 @@ class Err(Result[T, E]):
|
|
|
19
20
|
__slots__ = ("_error_value",)
|
|
20
21
|
__match_args__ = ("error",)
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
@overload
|
|
24
|
+
def __init__(self: Err[T, E], error: E) -> None: ...
|
|
25
|
+
|
|
26
|
+
@overload
|
|
27
|
+
def __init__(self: Err[T, Any], error: Any) -> None: ...
|
|
28
|
+
|
|
29
|
+
def __init__(self, error: E | Any) -> None:
|
|
30
|
+
self._error_value = cast(E, error)
|
|
24
31
|
|
|
25
32
|
def __repr__(self) -> str:
|
|
26
33
|
return f"Err({self._error_value!r})"
|
|
@@ -81,7 +88,7 @@ class Err(Result[T, E]):
|
|
|
81
88
|
def unwrap_or_raise(
|
|
82
89
|
self,
|
|
83
90
|
exc_type: type[BaseException] = Exception,
|
|
84
|
-
context:
|
|
91
|
+
context: str | None = None,
|
|
85
92
|
) -> T:
|
|
86
93
|
payload = self._error_value
|
|
87
94
|
msg = context if context is not None else str(payload)
|
rust_ok/ok.py
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from typing import Any, Literal, TypeVar, cast, overload
|
|
6
7
|
|
|
7
8
|
from .exceptions import IsNotError, UnwrapError
|
|
8
9
|
from .result import Result
|
|
@@ -22,12 +23,15 @@ class Ok(Result[T, E]):
|
|
|
22
23
|
value: T
|
|
23
24
|
|
|
24
25
|
@overload
|
|
25
|
-
def __init__(self:
|
|
26
|
+
def __init__(self: Ok[Any, Any]) -> None: ...
|
|
26
27
|
|
|
27
28
|
@overload
|
|
28
|
-
def __init__(self:
|
|
29
|
+
def __init__(self: Ok[None, E], value: Literal[None]) -> None: ...
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
@overload
|
|
32
|
+
def __init__(self: Ok[T, E], value: T) -> None: ...
|
|
33
|
+
|
|
34
|
+
def __init__(self, value: T | None = None) -> None:
|
|
31
35
|
self.value = cast(T, value)
|
|
32
36
|
|
|
33
37
|
def __repr__(self) -> str:
|
|
@@ -72,13 +76,13 @@ class Ok(Result[T, E]):
|
|
|
72
76
|
return Ok(func(self.value))
|
|
73
77
|
|
|
74
78
|
def map_err(self, func: Callable[[E], F]) -> Result[T, F]:
|
|
75
|
-
return Ok(self.value)
|
|
79
|
+
return cast(Result[T, F], Ok(self.value))
|
|
76
80
|
|
|
77
81
|
def and_then(self, func: Callable[[T], Result[U, E]]) -> Result[U, E]:
|
|
78
82
|
return func(self.value)
|
|
79
83
|
|
|
80
84
|
def or_else(self, func: Callable[[E], Result[T, F]]) -> Result[T, F]:
|
|
81
|
-
return Ok(self.value)
|
|
85
|
+
return cast(Result[T, F], Ok(self.value))
|
|
82
86
|
|
|
83
87
|
def ok(self) -> T:
|
|
84
88
|
return self.value
|
rust_ok/result.py
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from typing import Generic, TypeVar
|
|
6
7
|
|
|
7
8
|
T = TypeVar("T")
|
|
8
9
|
E = TypeVar("E")
|
|
@@ -79,7 +80,7 @@ class Result(Generic[T, E]):
|
|
|
79
80
|
def unwrap_or_raise(
|
|
80
81
|
self,
|
|
81
82
|
exc_type: type[BaseException] = Exception,
|
|
82
|
-
context:
|
|
83
|
+
context: str | None = None,
|
|
83
84
|
) -> T:
|
|
84
85
|
"""Return the Ok value or raise `exc_type`."""
|
|
85
86
|
raise NotImplementedError # pragma: no cover
|
rust_ok/trace.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: rust-ok
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Rust-inspired Result/Ok/Err primitives for Python
|
|
5
5
|
Keywords: result,error-handling,rust,functional,typing
|
|
6
6
|
Author: pesap
|
|
@@ -33,7 +33,7 @@ License: BSD 3-Clause License
|
|
|
33
33
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
34
34
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
35
35
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
36
|
-
Classifier: Development Status ::
|
|
36
|
+
Classifier: Development Status :: 4 - Beta
|
|
37
37
|
Classifier: Intended Audience :: Developers
|
|
38
38
|
Classifier: License :: OSI Approved :: BSD License
|
|
39
39
|
Classifier: Natural Language :: English
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
rust_ok/__init__.py,sha256=bPwWnvWo4gP5YZxYgcTFd5VlYNM1p37-r_32Ge6K6ic,523
|
|
2
|
+
rust_ok/err.py,sha256=Oa_wk5Mz27_VoKRQxfKzpMI3x8TmM5lfUHRxhawYnKA,2580
|
|
3
|
+
rust_ok/exceptions.py,sha256=G2FC6K6bBYrbpqUlf7paNp2M0aNWKPC_Onh5toVoOcs,325
|
|
4
|
+
rust_ok/guards.py,sha256=83zQfZPBERs1oO3qrHXrrw74rwKNnp9VQOLTlbjeZbM,496
|
|
5
|
+
rust_ok/ok.py,sha256=HrmPaFb7GEOuzzDjSJ4nhw_bcsnvgIIGBMiOJU3i0bc,2356
|
|
6
|
+
rust_ok/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
rust_ok/result.py,sha256=fSLMK3IGdFpVPxATgtJy4_wcDd_V8ezj_2zhLDJMsF0,2963
|
|
8
|
+
rust_ok/trace.py,sha256=yUSTkGC5U6rpFGoe6Yzrs4kN7DEkh5soCFO6JxNZAPw,1218
|
|
9
|
+
rust_ok-0.2.0.dist-info/WHEEL,sha256=ZyFSCYkV2BrxH6-HRVRg3R9Fo7MALzer9KiPYqNxSbo,79
|
|
10
|
+
rust_ok-0.2.0.dist-info/METADATA,sha256=K4_YpPWMdpyB88yCa3qHX9nVFaiWudCDWZy9wJMh8Ag,3300
|
|
11
|
+
rust_ok-0.2.0.dist-info/RECORD,,
|
rust_ok-0.1.0.dist-info/RECORD
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
rust_ok/__init__.py,sha256=QvHZuMC8oYbIesOeDINf9QkoD-CoQQXS7KFjPs3hIeA,430
|
|
2
|
-
rust_ok/err.py,sha256=L7YaUbGJzy7Q1XOKmx1iYGUuwQh1eWADUBhZrke6PDM,2382
|
|
3
|
-
rust_ok/exceptions.py,sha256=G2FC6K6bBYrbpqUlf7paNp2M0aNWKPC_Onh5toVoOcs,325
|
|
4
|
-
rust_ok/guards.py,sha256=83zQfZPBERs1oO3qrHXrrw74rwKNnp9VQOLTlbjeZbM,496
|
|
5
|
-
rust_ok/ok.py,sha256=iHj8dWyoB8J-VRQUpQgLJ8nWsS_xZIVAbnexeCqg8K0,2243
|
|
6
|
-
rust_ok/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
rust_ok/result.py,sha256=fdcI3WjXqaeHMEDaOXGCThuwz7SALtJ9aKKDwmg8628,2949
|
|
8
|
-
rust_ok/trace.py,sha256=WGuwRHMjCIiXztyLHLUIyNq2DfJbdZ1oW85FrrcZojo,1209
|
|
9
|
-
rust_ok-0.1.0.dist-info/WHEEL,sha256=ZHijuPszqKbNczrBXkSuoxdxocbxgFghqnequ9ZQlVk,79
|
|
10
|
-
rust_ok-0.1.0.dist-info/METADATA,sha256=rtE8Hk2Zfzq_2I08r2veZlCuVkkul-WsOKgMUyGQSNQ,3301
|
|
11
|
-
rust_ok-0.1.0.dist-info/RECORD,,
|