StructResult 0.9.2__tar.gz → 0.9.3__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.9.2 → structresult-0.9.3}/PKG-INFO +2 -2
- {structresult-0.9.2 → structresult-0.9.3}/pyproject.toml +2 -2
- {structresult-0.9.2 → structresult-0.9.3}/src/StructResult/result.py +47 -2
- {structresult-0.9.2 → structresult-0.9.3}/src/StructResult.egg-info/PKG-INFO +2 -2
- {structresult-0.9.2 → structresult-0.9.3}/src/StructResult.egg-info/requires.txt +1 -1
- {structresult-0.9.2 → structresult-0.9.3}/test/test_Sequence.py +4 -2
- {structresult-0.9.2 → structresult-0.9.3}/test/test_result.py +1 -1
- {structresult-0.9.2 → structresult-0.9.3}/README.md +0 -0
- {structresult-0.9.2 → structresult-0.9.3}/setup.cfg +0 -0
- {structresult-0.9.2 → structresult-0.9.3}/src/StructResult/__init__.py +0 -0
- {structresult-0.9.2 → structresult-0.9.3}/src/StructResult/formatter.py +0 -0
- {structresult-0.9.2 → structresult-0.9.3}/src/StructResult/py.typed +0 -0
- {structresult-0.9.2 → structresult-0.9.3}/src/StructResult.egg-info/SOURCES.txt +0 -0
- {structresult-0.9.2 → structresult-0.9.3}/src/StructResult.egg-info/dependency_links.txt +0 -0
- {structresult-0.9.2 → structresult-0.9.3}/src/StructResult.egg-info/top_level.txt +0 -0
- {structresult-0.9.2 → structresult-0.9.3}/test/benchmark.py +0 -0
- {structresult-0.9.2 → structresult-0.9.3}/test/test_formatter.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: StructResult
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.3
|
|
4
4
|
Summary: structural result with ExceptionGroup
|
|
5
5
|
Author-email: Serj Kotilevski <youserj@outlook.com>
|
|
6
6
|
Project-URL: Source, https://github.com/youserj/Result_prj
|
|
@@ -11,7 +11,7 @@ Classifier: Operating System :: OS Independent
|
|
|
11
11
|
Requires-Python: >=3.12
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
Provides-Extra: dev
|
|
14
|
-
Requires-Dist: mypy>=1.
|
|
14
|
+
Requires-Dist: mypy>=1.18.0; extra == "dev"
|
|
15
15
|
Requires-Dist: ruff>=0.11; extra == "dev"
|
|
16
16
|
Requires-Dist: types-requests; extra == "dev"
|
|
17
17
|
|
|
@@ -9,7 +9,7 @@ where = ["src"]
|
|
|
9
9
|
|
|
10
10
|
[project]
|
|
11
11
|
name = "StructResult"
|
|
12
|
-
version = "0.9.
|
|
12
|
+
version = "0.9.3"
|
|
13
13
|
requires-python = ">= 3.12"
|
|
14
14
|
authors = [
|
|
15
15
|
{name="Serj Kotilevski", email="youserj@outlook.com"}
|
|
@@ -34,7 +34,7 @@ Source = "https://github.com/youserj/Result_prj"
|
|
|
34
34
|
|
|
35
35
|
[project.optional-dependencies]
|
|
36
36
|
dev = [
|
|
37
|
-
"mypy>=1.
|
|
37
|
+
"mypy>=1.18.0",
|
|
38
38
|
"ruff>=0.11",
|
|
39
39
|
"types-requests"
|
|
40
40
|
]
|
|
@@ -24,6 +24,9 @@ class Result(Protocol):
|
|
|
24
24
|
def unwrap(self) -> Any:
|
|
25
25
|
"""Returns value or raises exception if errors exist"""
|
|
26
26
|
|
|
27
|
+
def has(self, target_value: Any, exception_type: Optional[type[Exception]] = None) -> bool:
|
|
28
|
+
""""""
|
|
29
|
+
|
|
27
30
|
|
|
28
31
|
class Ok(Result):
|
|
29
32
|
|
|
@@ -46,6 +49,9 @@ class Ok(Result):
|
|
|
46
49
|
def err(self) -> None: # type: ignore[override]
|
|
47
50
|
return None
|
|
48
51
|
|
|
52
|
+
def has(self, target_value: Any, exception_type: Optional[type[Exception]] = None) -> bool:
|
|
53
|
+
return False
|
|
54
|
+
|
|
49
55
|
|
|
50
56
|
OK = Ok()
|
|
51
57
|
|
|
@@ -99,6 +105,11 @@ class ErrorPropagator(Result, Protocol):
|
|
|
99
105
|
self.append_err(res.err)
|
|
100
106
|
return res.value if hasattr(res, "value") else NULL
|
|
101
107
|
|
|
108
|
+
def has(self, target_value: Any, exception_type: Optional[type[Exception]] = None) -> bool:
|
|
109
|
+
if self.err is None:
|
|
110
|
+
return False
|
|
111
|
+
return is_target(self.err, target_value, exception_type)
|
|
112
|
+
|
|
102
113
|
|
|
103
114
|
@dataclass(slots=True)
|
|
104
115
|
class Error(ErrorPropagator):
|
|
@@ -123,6 +134,9 @@ class Error(ErrorPropagator):
|
|
|
123
134
|
def value(self) -> Null:
|
|
124
135
|
return NULL
|
|
125
136
|
|
|
137
|
+
def has(self, target_value: Any, exception_type: Optional[type[Exception]] = None) -> bool:
|
|
138
|
+
return is_target(self.err, target_value, exception_type)
|
|
139
|
+
|
|
126
140
|
|
|
127
141
|
@dataclass(slots=True)
|
|
128
142
|
class StrictOk(ErrorPropagator):
|
|
@@ -170,6 +184,9 @@ class StrictOk(ErrorPropagator):
|
|
|
170
184
|
return Error(self.err)
|
|
171
185
|
|
|
172
186
|
|
|
187
|
+
type ValueOrError[T: Any] = T | Error
|
|
188
|
+
|
|
189
|
+
|
|
173
190
|
# todo: maybe will replaced by StrictOK
|
|
174
191
|
@dataclass(slots=True)
|
|
175
192
|
class ErrorAccumulator(ErrorPropagator):
|
|
@@ -177,7 +194,7 @@ class ErrorAccumulator(ErrorPropagator):
|
|
|
177
194
|
err: Optional[ExceptionGroup] = field(init=False, default=None)
|
|
178
195
|
|
|
179
196
|
@property
|
|
180
|
-
def result(self) -> Ok
|
|
197
|
+
def result(self) -> ValueOrError[Ok]:
|
|
181
198
|
"""
|
|
182
199
|
Finalize error accumulation and return simple Result.
|
|
183
200
|
Converts this accumulator to either:
|
|
@@ -229,6 +246,13 @@ class Collector[T](ErrorPropagator, Protocol):
|
|
|
229
246
|
raise self.err
|
|
230
247
|
return self.value
|
|
231
248
|
|
|
249
|
+
@property
|
|
250
|
+
def result(self) -> ValueOrError[T]:
|
|
251
|
+
"""Finalize Collection to Value or Error"""
|
|
252
|
+
if self.err is None:
|
|
253
|
+
return self.value
|
|
254
|
+
return Error(self.err)
|
|
255
|
+
|
|
232
256
|
|
|
233
257
|
@dataclass(slots=True)
|
|
234
258
|
class Simple[T](Collector[T], Result):
|
|
@@ -280,7 +304,6 @@ class List[T](Collector[list[Optional[T | Ok | Null]]], Result):
|
|
|
280
304
|
|
|
281
305
|
type SimpleOrError[T: Any] = Simple[T] | Error
|
|
282
306
|
|
|
283
|
-
|
|
284
307
|
T1 = TypeVar('T1')
|
|
285
308
|
|
|
286
309
|
|
|
@@ -330,6 +353,28 @@ class Sequence[*Ts](Collector[tuple[*Ts]], Result):
|
|
|
330
353
|
return f"({", ".join(map(str, self.value))}){"" if not self.err else str(self.err)}"
|
|
331
354
|
|
|
332
355
|
|
|
356
|
+
def is_target(exc_group: ExceptionGroup, target_value: Any, exception_type: Optional[type[Exception]] = None) -> bool:
|
|
357
|
+
"""
|
|
358
|
+
has target Exception in group
|
|
359
|
+
"""
|
|
360
|
+
stack = [exc_group]
|
|
361
|
+
while stack:
|
|
362
|
+
current = stack.pop()
|
|
363
|
+
for exc in current.exceptions:
|
|
364
|
+
if isinstance(exc, ExceptionGroup):
|
|
365
|
+
stack.append(exc)
|
|
366
|
+
elif (
|
|
367
|
+
(
|
|
368
|
+
exception_type is None
|
|
369
|
+
or isinstance(exc, exception_type)
|
|
370
|
+
)
|
|
371
|
+
and exc.args
|
|
372
|
+
and exc.args[0] == target_value
|
|
373
|
+
):
|
|
374
|
+
return True
|
|
375
|
+
return False
|
|
376
|
+
|
|
377
|
+
|
|
333
378
|
__all__ = [
|
|
334
379
|
"SimpleOrError"
|
|
335
380
|
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: StructResult
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.3
|
|
4
4
|
Summary: structural result with ExceptionGroup
|
|
5
5
|
Author-email: Serj Kotilevski <youserj@outlook.com>
|
|
6
6
|
Project-URL: Source, https://github.com/youserj/Result_prj
|
|
@@ -11,7 +11,7 @@ Classifier: Operating System :: OS Independent
|
|
|
11
11
|
Requires-Python: >=3.12
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
Provides-Extra: dev
|
|
14
|
-
Requires-Dist: mypy>=1.
|
|
14
|
+
Requires-Dist: mypy>=1.18.0; extra == "dev"
|
|
15
15
|
Requires-Dist: ruff>=0.11; extra == "dev"
|
|
16
16
|
Requires-Dist: types-requests; extra == "dev"
|
|
17
17
|
|
|
@@ -231,9 +231,11 @@ class TestSequenceAdd(unittest.TestCase):
|
|
|
231
231
|
def test_add_simple_value(self) -> None:
|
|
232
232
|
"""Test adding Simple value to sequence"""
|
|
233
233
|
seq1: Sequence[int, str] = Sequence(1, "hello")
|
|
234
|
-
simple_val = Simple(3.14)
|
|
235
|
-
|
|
234
|
+
simple_val = Simple(3.14).append_e(ValueError(), "val error1")
|
|
236
235
|
seq2 = seq1.add(simple_val)
|
|
236
|
+
res_err = Error.from_e(ValueError(), "val error2")
|
|
237
|
+
seq3 = seq2.add(res_err)
|
|
238
|
+
seq3 = seq3.add(Error.from_e(ValueError(), "val error1"))
|
|
237
239
|
|
|
238
240
|
self.assertEqual(seq2.value, (1, "hello", 3.14))
|
|
239
241
|
self.assertIsNone(seq2.err)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import unittest
|
|
2
2
|
from unittest.mock import patch
|
|
3
3
|
from typing import Any
|
|
4
|
-
from src.StructResult.result import Option, Bool, Ok, OK, Error, List, SimpleOrError, Simple, Sequence, Null
|
|
4
|
+
from src.StructResult.result import Option, Bool, Ok, OK, Error, List, SimpleOrError, Simple, Sequence, Null, is_target
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class TestResultSystem(unittest.TestCase):
|
|
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
|