UniversalFunctions 1.1.1__tar.gz → 1.2.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.
- {universalfunctions-1.1.1/UniversalFunctions.egg-info → universalfunctions-1.2.0}/PKG-INFO +1 -1
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/UF/Validators/QuantumValidators.py +15 -20
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/UF/Validators/ValidationClasses.py +79 -11
- {universalfunctions-1.1.1 → universalfunctions-1.2.0/UniversalFunctions.egg-info}/PKG-INFO +1 -1
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/pyproject.toml +1 -1
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/LICENSE +0 -0
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/README.md +0 -0
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/UF/ClassToDict.py +0 -0
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/UF/DecoratorArchive.py +0 -0
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/UF/GetVariable.py +0 -0
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/UF/HelperFunctions.py +0 -0
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/UF/StringCheck.py +0 -0
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/UF/Trigonometry.py +0 -0
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/UF/Validators/QuantumFuncValidators.py +0 -0
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/UF/Validators/__init__.py +0 -0
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/UF/__init__.py +0 -0
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/UniversalFunctions.egg-info/SOURCES.txt +0 -0
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/UniversalFunctions.egg-info/dependency_links.txt +0 -0
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/UniversalFunctions.egg-info/top_level.txt +0 -0
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/setup.cfg +0 -0
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/tests/__init__.py +0 -0
- {universalfunctions-1.1.1 → universalfunctions-1.2.0}/tests/test_ClassToDict.py +0 -0
|
@@ -3,15 +3,19 @@ This module contains type validators for list and tuple which belong to the QTM
|
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
5
|
from typing import Any, get_args, get_origin, Annotated
|
|
6
|
-
from .ValidationClasses import TypeValidate
|
|
6
|
+
from .ValidationClasses import TypeValidate, SequenceValidate
|
|
7
7
|
|
|
8
|
-
def qtm_lt_validator(value: list[Any] | tuple[Any, ...], TYPE: Any, name: str) ->
|
|
8
|
+
def qtm_lt_validator(value: list[Any] | tuple[Any, ...], TYPE: Any, name: str) -> tuple | list:
|
|
9
9
|
"""
|
|
10
|
-
Takes a list of
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
Takes a list/tuple of specific elements and validates its contents against the expected type
|
|
11
|
+
|
|
12
|
+
>>> qtm_lt_validator([1, 2, 3], list[int, ...], "random list")
|
|
13
|
+
[1, 2, 3]
|
|
14
|
+
|
|
15
|
+
:param value: list/tuple of elements
|
|
16
|
+
:param TYPE: list[expected type] for example
|
|
13
17
|
:param name: name of value
|
|
14
|
-
:return:
|
|
18
|
+
:return: validated list/tuple of elements
|
|
15
19
|
"""
|
|
16
20
|
origin = get_origin(TYPE)
|
|
17
21
|
if origin not in (list, tuple):
|
|
@@ -20,21 +24,11 @@ def qtm_lt_validator(value: list[Any] | tuple[Any, ...], TYPE: Any, name: str) -
|
|
|
20
24
|
TypeValidate(origin)(value)
|
|
21
25
|
|
|
22
26
|
element_type = get_args(TYPE)
|
|
23
|
-
|
|
24
|
-
if len(element_type) != 1:
|
|
25
|
-
raise TypeError("TYPE must contain only ONE type!")
|
|
26
|
-
|
|
27
|
-
elif origin is tuple:
|
|
28
|
-
if len(element_type) != 2 or element_type[1] is not Ellipsis:
|
|
29
|
-
raise TypeError("tuple TYPE must contain only ONE type with the form tuple[T, ...]!")
|
|
30
|
-
|
|
31
|
-
for index, element in enumerate(value):
|
|
32
|
-
if not isinstance(element, element_type[0]):
|
|
33
|
-
raise TypeError(f"{name}[{index}] must be of type {element_type[0].__name__!r}!")
|
|
27
|
+
validator = SequenceValidate(*element_type)
|
|
34
28
|
|
|
35
|
-
return
|
|
29
|
+
return validator(value, name=name)
|
|
36
30
|
|
|
37
|
-
def qtm_constr_validator(value, annotation, name) ->
|
|
31
|
+
def qtm_constr_validator(value: Any, annotation, name: str) -> Any:
|
|
38
32
|
"""
|
|
39
33
|
Takes a value and its annotation and compares it against the expected type
|
|
40
34
|
:param value: given value
|
|
@@ -48,9 +42,10 @@ def qtm_constr_validator(value, annotation, name) -> bool:
|
|
|
48
42
|
|
|
49
43
|
type_obj, *constraints = get_args(annotation)
|
|
50
44
|
|
|
45
|
+
TypeValidate(str)(name, name="name")
|
|
51
46
|
TypeValidate(type_obj)(value, name=name)
|
|
52
47
|
|
|
53
48
|
for constraint in constraints:
|
|
54
49
|
constraint(value)
|
|
55
50
|
|
|
56
|
-
return
|
|
51
|
+
return value
|
|
@@ -6,7 +6,18 @@ from collections.abc import Callable
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class TypeValidate:
|
|
9
|
-
"""
|
|
9
|
+
"""
|
|
10
|
+
Makes sure the entered value is of correct type.
|
|
11
|
+
|
|
12
|
+
>>> TypeValidate(float)(-30.9)
|
|
13
|
+
-30.9
|
|
14
|
+
>>> TypeValidate(str)('Hello World')
|
|
15
|
+
'Hello World'
|
|
16
|
+
>>> TypeValidate(int)(-10)
|
|
17
|
+
-10
|
|
18
|
+
>>> TypeValidate((list, int))([1, "2"])
|
|
19
|
+
[1, '2']
|
|
20
|
+
"""
|
|
10
21
|
def __init__(self, expected: type | tuple[type, ...]):
|
|
11
22
|
"""Makes sure the entered value is a type object"""
|
|
12
23
|
if isinstance(expected, tuple):
|
|
@@ -37,27 +48,50 @@ class TypeValidate:
|
|
|
37
48
|
return value
|
|
38
49
|
|
|
39
50
|
def int_validate() -> TypeValidate:
|
|
40
|
-
"""
|
|
51
|
+
"""
|
|
52
|
+
Makes sure the entered value is an integer with TypeValidate.
|
|
53
|
+
|
|
54
|
+
>>> int_validate()(-39)
|
|
55
|
+
-39
|
|
56
|
+
"""
|
|
41
57
|
return TypeValidate(int)
|
|
42
58
|
|
|
43
59
|
def str_validate() -> TypeValidate:
|
|
44
|
-
"""
|
|
60
|
+
"""
|
|
61
|
+
Makes sure the entered value is a string with TypeValidate.
|
|
62
|
+
|
|
63
|
+
>>> str_validate()('Hello World')
|
|
64
|
+
'Hello World'
|
|
65
|
+
"""
|
|
45
66
|
return TypeValidate(str)
|
|
46
67
|
|
|
47
68
|
def real_validate() -> TypeValidate:
|
|
48
|
-
"""
|
|
69
|
+
"""
|
|
70
|
+
Makes sure the entered value is a real number with TypeValidate.
|
|
71
|
+
|
|
72
|
+
>>> real_validate()(-10.5)
|
|
73
|
+
-10.5
|
|
74
|
+
"""
|
|
49
75
|
return TypeValidate(Real)
|
|
50
76
|
|
|
51
77
|
class RealValidationParent:
|
|
78
|
+
"""
|
|
79
|
+
Parent class for classes which require an expected real number value when an instance is made of them.
|
|
80
|
+
"""
|
|
52
81
|
def __init__(self, expected: Real) -> None:
|
|
53
82
|
self._validator = real_validate()
|
|
54
83
|
self._validator(expected)
|
|
55
84
|
self.expected = expected
|
|
56
85
|
|
|
57
86
|
class Positive:
|
|
58
|
-
"""
|
|
87
|
+
"""
|
|
88
|
+
Makes sure the entered value is positive.
|
|
89
|
+
|
|
90
|
+
>>> Positive()(50)
|
|
91
|
+
50
|
|
92
|
+
"""
|
|
59
93
|
def __call__(self, value: Real, name: str|None = None) -> Real:
|
|
60
|
-
"""Validates the entered value, expected to be positive (0
|
|
94
|
+
"""Validates the entered value, expected to be positive (above 0)"""
|
|
61
95
|
if name is not None:
|
|
62
96
|
real_validate()(value, name)
|
|
63
97
|
else:
|
|
@@ -67,7 +101,12 @@ class Positive:
|
|
|
67
101
|
return value
|
|
68
102
|
|
|
69
103
|
class LessThan(RealValidationParent):
|
|
70
|
-
"""
|
|
104
|
+
"""
|
|
105
|
+
Makes sure the entered value is less than expected value.
|
|
106
|
+
|
|
107
|
+
>>> LessThan(75)(10)
|
|
108
|
+
10
|
|
109
|
+
"""
|
|
71
110
|
def __call__(self, value: Real, name: str|None = None) -> Real:
|
|
72
111
|
"""Validates the entered value, expected to be less than expected value"""
|
|
73
112
|
self._validator(value)
|
|
@@ -78,7 +117,14 @@ class LessThan(RealValidationParent):
|
|
|
78
117
|
return value
|
|
79
118
|
|
|
80
119
|
class LessOrEqual(RealValidationParent):
|
|
81
|
-
"""
|
|
120
|
+
"""
|
|
121
|
+
Makes sure the entered value is less than or equal to expected value.
|
|
122
|
+
|
|
123
|
+
>>> LessOrEqual(100)(90)
|
|
124
|
+
90
|
|
125
|
+
>>> LessOrEqual(50)(50)
|
|
126
|
+
50
|
|
127
|
+
"""
|
|
82
128
|
def __call__(self, value: Real, name: str|None = None) -> Real:
|
|
83
129
|
"""Validates the entered value, expected to be less than or equal to expected value"""
|
|
84
130
|
self._validator(value)
|
|
@@ -90,7 +136,12 @@ class LessOrEqual(RealValidationParent):
|
|
|
90
136
|
|
|
91
137
|
|
|
92
138
|
class GreaterThan(RealValidationParent):
|
|
93
|
-
"""
|
|
139
|
+
"""
|
|
140
|
+
Makes sure the entered value is greater than expected value.
|
|
141
|
+
|
|
142
|
+
>>> GreaterThan(5)(10)
|
|
143
|
+
10
|
|
144
|
+
"""
|
|
94
145
|
def __call__(self, value: Real, name: str|None = None) -> Real:
|
|
95
146
|
"""Validates the entered value, expected to be greater than expected value"""
|
|
96
147
|
self._validator(value)
|
|
@@ -101,7 +152,14 @@ class GreaterThan(RealValidationParent):
|
|
|
101
152
|
return value
|
|
102
153
|
|
|
103
154
|
class GreaterOrEqual(RealValidationParent):
|
|
104
|
-
"""
|
|
155
|
+
"""
|
|
156
|
+
Makes sure the entered value is greater than or equal to expected value.
|
|
157
|
+
|
|
158
|
+
>>> GreaterOrEqual(5)(10)
|
|
159
|
+
10
|
|
160
|
+
>>> GreaterOrEqual(5)(5)
|
|
161
|
+
5
|
|
162
|
+
"""
|
|
105
163
|
def __call__(self, value: Real, name: str|None = None) -> Real:
|
|
106
164
|
"""Validates the entered value, expected to be greater than or equal to expected value"""
|
|
107
165
|
self._validator(value)
|
|
@@ -112,7 +170,17 @@ class GreaterOrEqual(RealValidationParent):
|
|
|
112
170
|
return value
|
|
113
171
|
|
|
114
172
|
class SequenceValidate:
|
|
115
|
-
"""
|
|
173
|
+
"""
|
|
174
|
+
Makes sure the entered value is a sequence of any value.
|
|
175
|
+
|
|
176
|
+
>>> validator = SequenceValidate(
|
|
177
|
+
... list,
|
|
178
|
+
... list,
|
|
179
|
+
... callable_items=(SequenceValidate(Real, ...),)
|
|
180
|
+
... )
|
|
181
|
+
>>> validator([[1, 2], [3, 4]])
|
|
182
|
+
[[1, 2], [3, 4]]
|
|
183
|
+
"""
|
|
116
184
|
def __init__(self, *expected: type | EllipsisType, **kwargs) -> None:
|
|
117
185
|
"""Validates and sets the tuple to a variable"""
|
|
118
186
|
for item in expected:
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "UniversalFunctions"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.2.0"
|
|
8
8
|
description = "A Python utility library providing foundational functions, validators, and infrastructure."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.14"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{universalfunctions-1.1.1 → universalfunctions-1.2.0}/UF/Validators/QuantumFuncValidators.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{universalfunctions-1.1.1 → universalfunctions-1.2.0}/UniversalFunctions.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{universalfunctions-1.1.1 → universalfunctions-1.2.0}/UniversalFunctions.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|