StructResult 0.1.0__tar.gz → 0.3.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.1.0 → structresult-0.3.0}/PKG-INFO +1 -1
- {structresult-0.1.0 → structresult-0.3.0}/pyproject.toml +1 -1
- structresult-0.3.0/src/StructResult/main.py +31 -0
- {structresult-0.1.0 → structresult-0.3.0}/src/StructResult.egg-info/PKG-INFO +1 -1
- {structresult-0.1.0 → structresult-0.3.0}/test/test_Result.py +2 -1
- structresult-0.1.0/src/StructResult/main.py +0 -21
- {structresult-0.1.0 → structresult-0.3.0}/README.md +0 -0
- {structresult-0.1.0 → structresult-0.3.0}/setup.cfg +0 -0
- {structresult-0.1.0 → structresult-0.3.0}/src/StructResult/__init__.py +0 -0
- {structresult-0.1.0 → structresult-0.3.0}/src/StructResult.egg-info/SOURCES.txt +0 -0
- {structresult-0.1.0 → structresult-0.3.0}/src/StructResult.egg-info/dependency_links.txt +0 -0
- {structresult-0.1.0 → structresult-0.3.0}/src/StructResult.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from typing import Optional, TypeVar, Generic
|
|
2
|
+
|
|
3
|
+
T = TypeVar("T")
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Result(Generic[T]):
|
|
7
|
+
value: T
|
|
8
|
+
err: Optional[list[Exception]]
|
|
9
|
+
__slots__ = ("value", "err")
|
|
10
|
+
|
|
11
|
+
def __init__(self, value: T, err: list[Exception] = None):
|
|
12
|
+
self.value = value
|
|
13
|
+
self.err = err
|
|
14
|
+
|
|
15
|
+
def __getitem__(self, item):
|
|
16
|
+
if item == 0:
|
|
17
|
+
return self.value
|
|
18
|
+
elif item == 1:
|
|
19
|
+
return self.err
|
|
20
|
+
else:
|
|
21
|
+
raise StopIteration
|
|
22
|
+
|
|
23
|
+
def append_err(self, e: Exception):
|
|
24
|
+
if self.err is None:
|
|
25
|
+
self.err = list()
|
|
26
|
+
self.err.append(e)
|
|
27
|
+
|
|
28
|
+
def extend_err(self, e: list[Exception]):
|
|
29
|
+
if self.err is None:
|
|
30
|
+
self.err = list()
|
|
31
|
+
self.err.extend(e)
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
from dataclasses import dataclass
|
|
2
|
-
from typing import Any, Optional
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
@dataclass(slots=True)
|
|
6
|
-
class Result:
|
|
7
|
-
value: Any
|
|
8
|
-
err: Optional[list[Exception]] = None
|
|
9
|
-
|
|
10
|
-
def __getitem__(self, item):
|
|
11
|
-
if item == 0:
|
|
12
|
-
return self.value
|
|
13
|
-
elif item == 1:
|
|
14
|
-
return self.err
|
|
15
|
-
else:
|
|
16
|
-
raise StopIteration
|
|
17
|
-
|
|
18
|
-
def append_err(self, e: Exception):
|
|
19
|
-
if self.err is None:
|
|
20
|
-
self.err = list()
|
|
21
|
-
self.err.append(e)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|