mm-std 0.4.7__py3-none-any.whl → 0.4.9__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.
mm_std/result.py
CHANGED
@@ -44,13 +44,30 @@ class Result[T]:
|
|
44
44
|
"""
|
45
45
|
return self.exception is not None
|
46
46
|
|
47
|
-
def unwrap(self) -> T:
|
47
|
+
def unwrap(self, message_prefix: str | None = None, include_error: bool = True) -> T:
|
48
48
|
"""
|
49
|
-
Returns the success value.
|
50
|
-
|
49
|
+
Returns the success value if the Result is Ok, otherwise raises a RuntimeError.
|
50
|
+
|
51
|
+
Args:
|
52
|
+
message_prefix: Optional custom prefix for the error message if the Result is an error.
|
53
|
+
If not provided, a default message will be used.
|
54
|
+
include_error: If True, appends the internal error message from the Result to the final exception message.
|
55
|
+
|
56
|
+
Raises:
|
57
|
+
RuntimeError: If the Result is an error.
|
58
|
+
|
59
|
+
Returns:
|
60
|
+
The success value of type T.
|
51
61
|
"""
|
52
62
|
if not self.is_ok():
|
53
|
-
|
63
|
+
# Use the provided message or a default fallback
|
64
|
+
error_message = message_prefix or "Called unwrap() on a failure value"
|
65
|
+
# Optionally append the error detail
|
66
|
+
if include_error:
|
67
|
+
error_message = f"{error_message}: {self.error}"
|
68
|
+
# Raise with the final constructed message
|
69
|
+
raise RuntimeError(error_message)
|
70
|
+
# Return the success value if present
|
54
71
|
return cast(T, self.value)
|
55
72
|
|
56
73
|
def unwrap_or(self, default: T) -> T:
|
@@ -79,7 +96,7 @@ class Result[T]:
|
|
79
96
|
return self.exception
|
80
97
|
raise RuntimeError("No exception provided")
|
81
98
|
|
82
|
-
def
|
99
|
+
def value_or_error(self) -> T | str:
|
83
100
|
"""
|
84
101
|
Returns the success value if available, otherwise returns the error message.
|
85
102
|
"""
|
@@ -12,7 +12,7 @@ mm_std/net.py,sha256=qdRCBIDneip6FaPNe5mx31UtYVmzqam_AoUF7ydEyjA,590
|
|
12
12
|
mm_std/print_.py,sha256=zB7sVbSSF8RffMxvnOdbKCXjCKtKzKV3R68pBri4NkQ,1638
|
13
13
|
mm_std/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
14
|
mm_std/random_.py,sha256=OuUX4VJeSd13NZBya4qrGpR2TfN7_87tfebOY6DBUnI,1113
|
15
|
-
mm_std/result.py,sha256=
|
15
|
+
mm_std/result.py,sha256=wzRdm8hzcvhKBD95NgQS7MklRMQQjVpgbsDAcolCMpg,9655
|
16
16
|
mm_std/str.py,sha256=BEjJ1p5O4-uSYK0h-enasSSDdwzkBbiwdQ4_dsrlEE8,3257
|
17
17
|
mm_std/toml.py,sha256=CNznWKR0bpOxS6e3VB5LGS-Oa9lW-wterkcPUFtPcls,610
|
18
18
|
mm_std/types_.py,sha256=9FGd2q47a8M9QQgsWJR1Kq34jLxBAkYSoJuwih4PPqg,257
|
@@ -28,6 +28,6 @@ mm_std/http/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
28
28
|
mm_std/http/http_request.py,sha256=VnjZKrfaXQfMxrHRUqQ-Sxtr5Qf9FXBiJ-mmJTCzNkY,3709
|
29
29
|
mm_std/http/http_request_sync.py,sha256=bqCBilbe4ZJ9vkhuBQeU5UMTJh6BtvtUwjieEodu6rw,1542
|
30
30
|
mm_std/http/http_response.py,sha256=vrRv7Rjr5_kTUGllfW5oJ8ZqkcfiXc9T8PlBGAr-TBM,3884
|
31
|
-
mm_std-0.4.
|
32
|
-
mm_std-0.4.
|
33
|
-
mm_std-0.4.
|
31
|
+
mm_std-0.4.9.dist-info/METADATA,sha256=W70MWq3UfeFan-QnCTqG_KArTapiIlNKqQN1bXZrozo,446
|
32
|
+
mm_std-0.4.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
33
|
+
mm_std-0.4.9.dist-info/RECORD,,
|
File without changes
|