error-values 0.1.4__tar.gz → 0.1.6__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.
- {error_values-0.1.4 → error_values-0.1.6}/PKG-INFO +8 -5
- {error_values-0.1.4 → error_values-0.1.6}/error_values.egg-info/PKG-INFO +8 -5
- error_values-0.1.6/error_values.egg-info/SOURCES.txt +4 -0
- error_values-0.1.4/error_values/error_values/__init__.py +0 -0
- error_values-0.1.4/error_values/error_values/errors.py +0 -79
- error_values-0.1.4/error_values/setup.py +0 -13
- error_values-0.1.4/error_values.egg-info/SOURCES.txt +0 -7
- {error_values-0.1.4 → error_values-0.1.6}/error_values.egg-info/dependency_links.txt +0 -0
- {error_values-0.1.4 → error_values-0.1.6}/error_values.egg-info/top_level.txt +0 -0
- {error_values-0.1.4 → error_values-0.1.6}/setup.cfg +0 -0
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: error_values
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.6
|
|
4
4
|
Description-Content-Type: text/markdown
|
|
5
5
|
Dynamic: description
|
|
6
6
|
Dynamic: description-content-type
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
# Potential errors in python
|
|
9
|
+
|
|
9
10
|
this package allows you to handle errors like in go and rust.
|
|
10
11
|
|
|
11
|
-
Inorder to do this, you must first install the package using ```pip install error-values```. Then you must import it into your prodjects like so ```import error_values``` or better ```from error_values import
|
|
12
|
+
Inorder to do this, you must first install the package using ```pip install error-values```. Then you must import it into your prodjects like so ```import error_values``` or better ```from error_values.error_value import errors```.
|
|
12
13
|
|
|
13
14
|
After that, you can use the ```Potential_Error``` class for safe results, you can do so like this ```Potential_Error("random string")```, meanwhile for dangerous result, you can do this ```Potential_Error(None,Random_Error)```.
|
|
14
15
|
|
|
15
|
-
Inorder to get the result you must use the dwrap method like so ```exsample.dewrap()```, only AFTER you get the stat from the ```stat``` method, and handle the errors like so
|
|
16
|
-
|
|
16
|
+
Inorder to get the result you must use the dwrap method like so ```exsample.dewrap()```, only AFTER you get the stat from the ```stat``` method, and handle the errors like so
|
|
17
|
+
|
|
18
|
+
``` python
|
|
17
19
|
exsampl = Potential_Error("random string")
|
|
18
20
|
if exsample.stat() == Result.FAIL:
|
|
19
21
|
# handleing error
|
|
20
22
|
dewrapped_value = exsample.dewrap()
|
|
21
23
|
# do what you want
|
|
22
24
|
```
|
|
25
|
+
|
|
23
26
|
along with this, you're able accses the error directly by using the ```.error``` class variable.
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: error_values
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.6
|
|
4
4
|
Description-Content-Type: text/markdown
|
|
5
5
|
Dynamic: description
|
|
6
6
|
Dynamic: description-content-type
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
# Potential errors in python
|
|
9
|
+
|
|
9
10
|
this package allows you to handle errors like in go and rust.
|
|
10
11
|
|
|
11
|
-
Inorder to do this, you must first install the package using ```pip install error-values```. Then you must import it into your prodjects like so ```import error_values``` or better ```from error_values import
|
|
12
|
+
Inorder to do this, you must first install the package using ```pip install error-values```. Then you must import it into your prodjects like so ```import error_values``` or better ```from error_values.error_value import errors```.
|
|
12
13
|
|
|
13
14
|
After that, you can use the ```Potential_Error``` class for safe results, you can do so like this ```Potential_Error("random string")```, meanwhile for dangerous result, you can do this ```Potential_Error(None,Random_Error)```.
|
|
14
15
|
|
|
15
|
-
Inorder to get the result you must use the dwrap method like so ```exsample.dewrap()```, only AFTER you get the stat from the ```stat``` method, and handle the errors like so
|
|
16
|
-
|
|
16
|
+
Inorder to get the result you must use the dwrap method like so ```exsample.dewrap()```, only AFTER you get the stat from the ```stat``` method, and handle the errors like so
|
|
17
|
+
|
|
18
|
+
``` python
|
|
17
19
|
exsampl = Potential_Error("random string")
|
|
18
20
|
if exsample.stat() == Result.FAIL:
|
|
19
21
|
# handleing error
|
|
20
22
|
dewrapped_value = exsample.dewrap()
|
|
21
23
|
# do what you want
|
|
22
24
|
```
|
|
25
|
+
|
|
23
26
|
along with this, you're able accses the error directly by using the ```.error``` class variable.
|
|
File without changes
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
from enum import Enum,auto
|
|
2
|
-
from typing import Generic,TypeVar,Optional,Any
|
|
3
|
-
from inspect import isclass
|
|
4
|
-
|
|
5
|
-
class Result(Enum):
|
|
6
|
-
FAIL = auto()
|
|
7
|
-
PASS = auto()
|
|
8
|
-
|
|
9
|
-
T = TypeVar("T",bound=Exception)
|
|
10
|
-
U = TypeVar("U")
|
|
11
|
-
|
|
12
|
-
class No_Error(Exception):
|
|
13
|
-
"""this is no errors and this is created to put in the scond type in Potential_Error if there is no error"""
|
|
14
|
-
pass
|
|
15
|
-
|
|
16
|
-
class Did_Not_Handeled_Exception(Exception):
|
|
17
|
-
pass
|
|
18
|
-
|
|
19
|
-
class Attmped_To_Dewrap_While_Have_Error(Exception):
|
|
20
|
-
pass
|
|
21
|
-
|
|
22
|
-
class Potential_Error(Generic[U,T]):
|
|
23
|
-
|
|
24
|
-
def __init__(self,value:U,error:Optional[T] = None):
|
|
25
|
-
self.__val = value
|
|
26
|
-
self.error = error
|
|
27
|
-
self.handled = False
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def stat(self) -> Result:
|
|
31
|
-
self.Handled = True
|
|
32
|
-
return self.raw_stat()
|
|
33
|
-
|
|
34
|
-
def dewrap(self) -> U:
|
|
35
|
-
"""this return the value, only if you handle the cas that it is an error."""
|
|
36
|
-
if self.Handled:
|
|
37
|
-
return self.__val
|
|
38
|
-
if self.error != No_Error:
|
|
39
|
-
raise Attmped_To_Dewrap_While_Have_Error("you mustn't have errors inorder to dewrapp")
|
|
40
|
-
raise Did_Not_Handeled_Exception("you forgot to handle the speciel case. That case being if an error occured. Inordr to fix this you must call the stat method, thn do this")
|
|
41
|
-
|
|
42
|
-
def raw_stat(self):
|
|
43
|
-
"""this makes it so that it deosn't remember that it handle the variable."""
|
|
44
|
-
if self.error == None or isinstance(self.error,No_Error):
|
|
45
|
-
return Result.PASS
|
|
46
|
-
else:
|
|
47
|
-
return Result.FAIL
|
|
48
|
-
|
|
49
|
-
def raise_error(self) -> None:
|
|
50
|
-
raise self.error # type: ignore
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def potential_error_wrap(val: Any):
|
|
54
|
-
if isclass(val) and issubclass(val, Exception):
|
|
55
|
-
return Potential_Error(None, val())
|
|
56
|
-
if issubclass(type(val),Exception):
|
|
57
|
-
return Potential_Error(None, val) #type:ignore
|
|
58
|
-
else:
|
|
59
|
-
return Potential_Error(val, No_Error())
|
|
60
|
-
|
|
61
|
-
def func_result_to_potential_error(func):
|
|
62
|
-
"""
|
|
63
|
-
this is a wrappr for functions, the reason for this is so
|
|
64
|
-
that you don't have to write potential_error_wrap all the time
|
|
65
|
-
"""
|
|
66
|
-
def auto_wrap(*args,**kwargs):
|
|
67
|
-
result = func(args,kwargs)
|
|
68
|
-
return potential_error_wrap(result)
|
|
69
|
-
return auto_wrap
|
|
70
|
-
|
|
71
|
-
def dangerous_func_to_potntial_error(func):
|
|
72
|
-
"""this is for functions with raise"""
|
|
73
|
-
def auto_wrap(*args,**kwargs):
|
|
74
|
-
try:
|
|
75
|
-
result = func(args,kwargs)
|
|
76
|
-
return potential_error_wrap(result)
|
|
77
|
-
except Exception as e:
|
|
78
|
-
return potential_error_wrap(e)
|
|
79
|
-
return auto_wrap
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
from setuptools import setup,find_packages
|
|
2
|
-
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
this_directory = Path(__file__).parent
|
|
5
|
-
long_description = (this_directory / "README.md").read_text()
|
|
6
|
-
|
|
7
|
-
setup(
|
|
8
|
-
name="error_values",
|
|
9
|
-
version="0.1.4",
|
|
10
|
-
packages=find_packages(),
|
|
11
|
-
long_description=long_description,
|
|
12
|
-
long_description_content_type='text/markdown'
|
|
13
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|