error-values 0.1__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.
@@ -0,0 +1,3 @@
1
+ Metadata-Version: 2.4
2
+ Name: error_values
3
+ Version: 0.1
File without changes
@@ -0,0 +1,81 @@
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 and self.Error == No_Error:
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
+ """
67
+ def auto_wrap(*args,**kwargs):
68
+ result = func(args,kwargs)
69
+ return potential_error_wrap(result)
70
+ return auto_wrap
71
+
72
+ def dangerous_func_to_potntial_error(func):
73
+ """this is for functions with raise"""
74
+ def auto_wrap(*args,**kwargs):
75
+ try:
76
+ result = func(args,kwargs)
77
+ return potential_error_wrap(result)
78
+ except Exception as e:
79
+ return potential_error_wrap(e)
80
+ return auto_wrap
81
+
@@ -0,0 +1,7 @@
1
+ from setuptools import setup,find_packages
2
+
3
+ setup(
4
+ name="error_values",
5
+ version="0.1"
6
+
7
+ )
@@ -0,0 +1,3 @@
1
+ Metadata-Version: 2.4
2
+ Name: error_values
3
+ Version: 0.1
@@ -0,0 +1,7 @@
1
+ error_values/setup.py
2
+ error_values.egg-info/PKG-INFO
3
+ error_values.egg-info/SOURCES.txt
4
+ error_values.egg-info/dependency_links.txt
5
+ error_values.egg-info/top_level.txt
6
+ error_values/error_values/__init__.py
7
+ error_values/error_values/errors.py
@@ -0,0 +1 @@
1
+ error_values
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+