StructResult 0.5.0__tar.gz → 0.5.2__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.5.0 → structresult-0.5.2}/PKG-INFO +3 -3
- {structresult-0.5.0 → structresult-0.5.2}/pyproject.toml +8 -3
- {structresult-0.5.0 → structresult-0.5.2}/src/StructResult/result.py +8 -5
- {structresult-0.5.0 → structresult-0.5.2}/src/StructResult.egg-info/PKG-INFO +3 -3
- {structresult-0.5.0 → structresult-0.5.2}/test/test_Result.py +11 -11
- {structresult-0.5.0 → structresult-0.5.2}/README.md +0 -0
- {structresult-0.5.0 → structresult-0.5.2}/setup.cfg +0 -0
- {structresult-0.5.0 → structresult-0.5.2}/src/StructResult/__init__.py +0 -0
- {structresult-0.5.0 → structresult-0.5.2}/src/StructResult.egg-info/SOURCES.txt +0 -0
- {structresult-0.5.0 → structresult-0.5.2}/src/StructResult.egg-info/dependency_links.txt +0 -0
- {structresult-0.5.0 → structresult-0.5.2}/src/StructResult.egg-info/top_level.txt +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: StructResult
|
|
3
|
-
Version: 0.5.
|
|
4
|
-
Summary: structural result with
|
|
3
|
+
Version: 0.5.2
|
|
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
|
|
7
|
-
Keywords: result,
|
|
7
|
+
Keywords: result,Exception,ExceptionGroup,AggregateExceptions
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
@@ -9,16 +9,21 @@ where = ["src"]
|
|
|
9
9
|
|
|
10
10
|
[project]
|
|
11
11
|
name = "StructResult"
|
|
12
|
-
version = "0.5.
|
|
12
|
+
version = "0.5.2"
|
|
13
13
|
requires-python = ">= 3.12"
|
|
14
14
|
authors = [
|
|
15
15
|
{name="Serj Kotilevski", email="youserj@outlook.com"}
|
|
16
16
|
]
|
|
17
17
|
dependencies = [
|
|
18
18
|
]
|
|
19
|
-
description="structural result with
|
|
19
|
+
description="structural result with ExceptionGroup"
|
|
20
20
|
readme = "README.md"
|
|
21
|
-
keywords=[
|
|
21
|
+
keywords=[
|
|
22
|
+
'result',
|
|
23
|
+
'Exception',
|
|
24
|
+
'ExceptionGroup',
|
|
25
|
+
'AggregateExceptions'
|
|
26
|
+
]
|
|
22
27
|
classifiers = [
|
|
23
28
|
"Programming Language :: Python :: 3",
|
|
24
29
|
"License :: OSI Approved :: MIT License",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Optional, TypeVar, Generic, Self
|
|
1
|
+
from typing import Optional, TypeVar, Generic, Self, Any
|
|
2
2
|
from abc import ABC, abstractmethod
|
|
3
3
|
|
|
4
4
|
T = TypeVar("T")
|
|
@@ -21,7 +21,7 @@ class Result(Generic[T], ABC):
|
|
|
21
21
|
raise StopIteration
|
|
22
22
|
|
|
23
23
|
@abstractmethod
|
|
24
|
-
def append(self, res: Self):
|
|
24
|
+
def append(self, res: Self) -> T:
|
|
25
25
|
""""""
|
|
26
26
|
|
|
27
27
|
def append_err(self, e: Exception | ExceptionGroup):
|
|
@@ -60,11 +60,12 @@ class Simple(Result, Generic[T]):
|
|
|
60
60
|
self.err = None
|
|
61
61
|
self.msg = msg
|
|
62
62
|
|
|
63
|
-
def append(self, res: Result):
|
|
63
|
+
def append(self, res: Result) -> T:
|
|
64
64
|
"""set value and append errors"""
|
|
65
65
|
self.value = res.value
|
|
66
66
|
if res.err is not None:
|
|
67
67
|
self.append_err(res.err)
|
|
68
|
+
return res.value
|
|
68
69
|
|
|
69
70
|
|
|
70
71
|
class Null(Result):
|
|
@@ -97,9 +98,10 @@ class Error(Result):
|
|
|
97
98
|
self.err = None
|
|
98
99
|
self.msg = msg
|
|
99
100
|
|
|
100
|
-
def append(self, res: Result):
|
|
101
|
+
def append(self, res: Result) -> Any:
|
|
101
102
|
if res.err is not None:
|
|
102
103
|
self.append_err(res.err)
|
|
104
|
+
return res.value
|
|
103
105
|
|
|
104
106
|
@property
|
|
105
107
|
def value(self):
|
|
@@ -115,11 +117,12 @@ class List(Result, Generic[T]):
|
|
|
115
117
|
self.err = None
|
|
116
118
|
self.msg = msg
|
|
117
119
|
|
|
118
|
-
def append(self, res: Result[T]):
|
|
120
|
+
def append(self, res: Result[T]) -> T:
|
|
119
121
|
"""append value and errors"""
|
|
120
122
|
self.value.append(res.value)
|
|
121
123
|
if res.err is not None:
|
|
122
124
|
self.append_err(res.err)
|
|
125
|
+
return res.value[-1]
|
|
123
126
|
|
|
124
127
|
def __add__(self, other: Result[T]) -> Self:
|
|
125
128
|
self.append(other)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: StructResult
|
|
3
|
-
Version: 0.5.
|
|
4
|
-
Summary: structural result with
|
|
3
|
+
Version: 0.5.2
|
|
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
|
|
7
|
-
Keywords: result,
|
|
7
|
+
Keywords: result,Exception,ExceptionGroup,AggregateExceptions
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
@@ -50,7 +50,7 @@ class TestType(unittest.TestCase):
|
|
|
50
50
|
def test_simple_append_error(self):
|
|
51
51
|
# Test appending an error Simple result
|
|
52
52
|
res1 = result.Simple(10)
|
|
53
|
-
res2 = result.Simple(
|
|
53
|
+
res2 = result.Simple(e=ValueError("test error"), msg="test")
|
|
54
54
|
res1.append(res2)
|
|
55
55
|
self.assertEqual(res1.value, None)
|
|
56
56
|
self.assertIsNotNone(res1.err)
|
|
@@ -58,15 +58,15 @@ class TestType(unittest.TestCase):
|
|
|
58
58
|
|
|
59
59
|
def test_simple_append_multiple_errors(self):
|
|
60
60
|
# Test error aggregation
|
|
61
|
-
res1 = result.Simple(
|
|
62
|
-
res2 = result.Simple(
|
|
61
|
+
res1 = result.Simple(e=TypeError("type error"), msg="test")
|
|
62
|
+
res2 = result.Simple(e=ValueError("value error"), msg="test")
|
|
63
63
|
res1.append(res2)
|
|
64
64
|
self.assertEqual(len(res1.err.exceptions), 2)
|
|
65
65
|
|
|
66
66
|
def test_simple_append_different_messages(self):
|
|
67
67
|
# Test error aggregation with different messages
|
|
68
|
-
res1 = result.Simple(
|
|
69
|
-
res2 = result.Simple(
|
|
68
|
+
res1 = result.Simple(e=TypeError("type error"), msg="test1")
|
|
69
|
+
res2 = result.Simple(e=ValueError("value error"), msg="test2")
|
|
70
70
|
res1.append(res2)
|
|
71
71
|
# Should nest the exception groups
|
|
72
72
|
self.assertEqual(len(res1.err.exceptions), 2)
|
|
@@ -79,15 +79,15 @@ class TestType(unittest.TestCase):
|
|
|
79
79
|
|
|
80
80
|
def test_error_append_value(self):
|
|
81
81
|
# Test that Error ignores values but collects errors
|
|
82
|
-
err1 = result.Error(
|
|
82
|
+
err1 = result.Error(e=ValueError("error1"), msg="test")
|
|
83
83
|
simple = result.Simple(10)
|
|
84
84
|
err1.append(simple)
|
|
85
85
|
self.assertIsNone(err1.value)
|
|
86
86
|
|
|
87
87
|
def test_error_append_error(self):
|
|
88
88
|
# Test error aggregation in Error class
|
|
89
|
-
err1 = result.Error(
|
|
90
|
-
err2 = result.Error(
|
|
89
|
+
err1 = result.Error(e=ValueError("error1"), msg="test")
|
|
90
|
+
err2 = result.Error(e=TypeError("error2"), msg="test")
|
|
91
91
|
err1.append(err2)
|
|
92
92
|
self.assertEqual(len(err1.err.exceptions), 2)
|
|
93
93
|
|
|
@@ -104,9 +104,9 @@ class TestType(unittest.TestCase):
|
|
|
104
104
|
# Test mixed success and error cases
|
|
105
105
|
lst = result.List[int](msg="test")
|
|
106
106
|
lst.append(result.Simple(1))
|
|
107
|
-
lst.append(result.Simple(
|
|
107
|
+
lst.append(result.Simple(e=ValueError("error1")))
|
|
108
108
|
lst.append(result.Simple(2))
|
|
109
|
-
lst.append(result.Simple(
|
|
109
|
+
lst.append(result.Simple(e=TypeError("error2")))
|
|
110
110
|
self.assertEqual(lst.value, [1, None, 2, None])
|
|
111
111
|
self.assertEqual(len(lst.err.exceptions), 2)
|
|
112
112
|
|
|
@@ -121,4 +121,4 @@ class TestType(unittest.TestCase):
|
|
|
121
121
|
# Test type safety (should ideally fail but currently doesn't)
|
|
122
122
|
lst = result.List[int]()
|
|
123
123
|
lst.append(result.Simple("string")) # This should ideally raise TypeError
|
|
124
|
-
self.assertEqual(lst.value, ["string"])
|
|
124
|
+
self.assertEqual(lst.value, ["string"])
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|