StructResult 0.3.1__tar.gz → 0.4.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.
- {structresult-0.3.1 → structresult-0.4.0}/PKG-INFO +1 -1
- {structresult-0.3.1 → structresult-0.4.0}/pyproject.toml +1 -1
- structresult-0.4.0/src/StructResult/__init__.py +1 -0
- {structresult-0.3.1 → structresult-0.4.0}/src/StructResult/main.py +14 -1
- {structresult-0.3.1 → structresult-0.4.0}/src/StructResult.egg-info/PKG-INFO +1 -1
- structresult-0.4.0/test/test_Result.py +23 -0
- structresult-0.3.1/src/StructResult/__init__.py +0 -1
- structresult-0.3.1/test/test_Result.py +0 -10
- {structresult-0.3.1 → structresult-0.4.0}/README.md +0 -0
- {structresult-0.3.1 → structresult-0.4.0}/setup.cfg +0 -0
- {structresult-0.3.1 → structresult-0.4.0}/src/StructResult.egg-info/SOURCES.txt +0 -0
- {structresult-0.3.1 → structresult-0.4.0}/src/StructResult.egg-info/dependency_links.txt +0 -0
- {structresult-0.3.1 → structresult-0.4.0}/src/StructResult.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .main import Result, ResultList
|
|
@@ -8,7 +8,7 @@ class Result(Generic[T]):
|
|
|
8
8
|
err: Optional[list[Exception]]
|
|
9
9
|
__slots__ = ("value", "err")
|
|
10
10
|
|
|
11
|
-
def __init__(self, value: T, err: list[Exception] = None):
|
|
11
|
+
def __init__(self, value: Optional[T], err: list[Exception] = None):
|
|
12
12
|
self.value = value
|
|
13
13
|
self.err = err
|
|
14
14
|
|
|
@@ -29,3 +29,16 @@ class Result(Generic[T]):
|
|
|
29
29
|
if self.err is None:
|
|
30
30
|
self.err = list()
|
|
31
31
|
self.err.extend(e)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ResultList(Result, Generic[T]):
|
|
35
|
+
value: list[T]
|
|
36
|
+
__slots__ = ("value", "err")
|
|
37
|
+
|
|
38
|
+
def __init__(self):
|
|
39
|
+
super().__init__(list())
|
|
40
|
+
|
|
41
|
+
def append(self, res: Result[T]):
|
|
42
|
+
self.value.append(res.value)
|
|
43
|
+
if res.err is not None:
|
|
44
|
+
self.extend_err(res.err)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from StructResult import Result, ResultList
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class TestType(unittest.TestCase):
|
|
6
|
+
|
|
7
|
+
def test_init(self):
|
|
8
|
+
res = Result[int](1)
|
|
9
|
+
self.assertEqual(res.value, 1)
|
|
10
|
+
self.assertEqual(list(res), [1, None])
|
|
11
|
+
|
|
12
|
+
def test_Optional(self):
|
|
13
|
+
|
|
14
|
+
def foo() -> Result[int]:
|
|
15
|
+
return Result(None)
|
|
16
|
+
|
|
17
|
+
def test_ResultList(self):
|
|
18
|
+
res = ResultList[int]()
|
|
19
|
+
res.append(Result(1, [ValueError("1")]))
|
|
20
|
+
res.append(Result(2))
|
|
21
|
+
res.append(Result(None, [ZeroDivisionError()]))
|
|
22
|
+
res.append(Result("1"))
|
|
23
|
+
print(res)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from .main import Result
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|