error-values 0.1.7__tar.gz → 0.1.8__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.
@@ -1,12 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: error_values
3
- Version: 0.1.7
3
+ Version: 0.1.8
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
+ github page <https://github.com/codingpwlorsk/error_vals_in_python>
11
+
10
12
  this package allows you to handle errors like in go and rust.
11
13
 
12
14
  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```.
@@ -0,0 +1,21 @@
1
+ # Potential errors in python
2
+
3
+ github page <https://github.com/codingpwlorsk/error_vals_in_python>
4
+
5
+ this package allows you to handle errors like in go and rust.
6
+
7
+ 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```.
8
+
9
+ 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)```.
10
+
11
+ 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
12
+
13
+ ``` python
14
+ exsampl = Potential_Error("random string")
15
+ if exsample.stat() == Result.FAIL:
16
+ # handleing error
17
+ dewrapped_value = exsample.dewrap()
18
+ # do what you want
19
+ ```
20
+
21
+ along with this, you're able accses the error directly by using the ```.error``` class variable.
@@ -0,0 +1 @@
1
+ import errors
@@ -0,0 +1,106 @@
1
+ from enum import Enum, auto
2
+ from typing import Generic, TypeVar, Optional, Any
3
+ from inspect import isclass
4
+
5
+
6
+ class Result(Enum):
7
+ FAIL = auto()
8
+ PASS = auto()
9
+
10
+
11
+ T = TypeVar("T", bound=Exception)
12
+ U = TypeVar("U")
13
+
14
+
15
+ class No_Error(Exception):
16
+ """
17
+ this is no errors and this is created to
18
+ put in the scond type in Potential_Error if there is no error
19
+ """
20
+ pass
21
+
22
+
23
+ class Did_Not_Handeled_Exception(Exception):
24
+ pass
25
+
26
+
27
+ class Attmped_To_Dewrap_While_Have_Error(Exception):
28
+ pass
29
+
30
+
31
+ class Potential_Error(Generic[U, T]):
32
+
33
+ def __init__(self, value: U, error: Optional[T] = None):
34
+ self.__val = value
35
+ if error is None:
36
+ self.error = No_Error()
37
+ else:
38
+ self.error = error
39
+ self.handled = False
40
+
41
+ def stat(self) -> Result:
42
+ self.Handled = True
43
+ return self.raw_stat()
44
+
45
+ def dewrap(self) -> U:
46
+ """this return the value, only if
47
+ you handle the cas that it is an error."""
48
+ if self.Handled:
49
+ return self.__val
50
+ if self.error != No_Error:
51
+ raise Attmped_To_Dewrap_While_Have_Error(
52
+ "you mustn't have errors "
53
+ "inorder to dewrapp")
54
+ raise Did_Not_Handeled_Exception(
55
+ "you forgot to handle the "
56
+ "speciel case. That case "
57
+ "being if an error "
58
+ "occured. Inordr to fix "
59
+ "this you must call the "
60
+ "stat method, then do this")
61
+
62
+ def raw_stat(self):
63
+ """
64
+ this makes it so that it deosn't remember that
65
+ it handle the variable.
66
+ """
67
+ if self.error is None or isinstance(self.error, No_Error):
68
+ return Result.PASS
69
+ else:
70
+ return Result.FAIL
71
+
72
+ def raise_error(self) -> None:
73
+ raise self.error # type: ignore
74
+
75
+
76
+ def potential_error_wrap(val: Any):
77
+ if isclass(val) and issubclass(val, Exception):
78
+ return Potential_Error(None, val())
79
+ if issubclass(type(val), Exception):
80
+ return Potential_Error(None, val) # type:ignore
81
+ else:
82
+ return Potential_Error(val, No_Error())
83
+
84
+
85
+ def func_result_to_potential_error(func):
86
+ """
87
+ this is a wrappr for functions, the reason for this is so
88
+ that you don't have to write potential_error_wrap all the time
89
+ """
90
+ def auto_wrap(*args, **kwargs):
91
+ result = func(args, kwargs)
92
+ return potential_error_wrap(result)
93
+ return auto_wrap
94
+
95
+
96
+ def dangerous_func_to_potntial_error(func):
97
+ """
98
+ this is for functions with raise
99
+ """
100
+ def auto_wrap(*args, **kwargs):
101
+ try:
102
+ result = func(args, kwargs)
103
+ return potential_error_wrap(result)
104
+ except Exception as e:
105
+ return potential_error_wrap(e)
106
+ return auto_wrap
@@ -1,12 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: error_values
3
- Version: 0.1.7
3
+ Version: 0.1.8
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
+ github page <https://github.com/codingpwlorsk/error_vals_in_python>
11
+
10
12
  this package allows you to handle errors like in go and rust.
11
13
 
12
14
  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```.
@@ -1,3 +1,7 @@
1
+ README.md
2
+ setup.py
3
+ error_values/__init__.py
4
+ error_values/errors.py
1
5
  error_values.egg-info/PKG-INFO
2
6
  error_values.egg-info/SOURCES.txt
3
7
  error_values.egg-info/dependency_links.txt
@@ -0,0 +1 @@
1
+ error_values
@@ -0,0 +1,13 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ # read the contents of your README file
4
+ from pathlib import Path
5
+ this_directory = Path(__file__).parent
6
+ long_description = (this_directory / "README.md").read_text()
7
+
8
+ setup(
9
+ name="error_values",
10
+ version="0.1.8",
11
+ packages=find_packages(),
12
+ long_description=long_description,
13
+ long_description_content_type='text/markdown')
File without changes