UniversalFunctions 1.1.1__tar.gz → 1.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.
Files changed (23) hide show
  1. {universalfunctions-1.1.1/UniversalFunctions.egg-info → universalfunctions-1.3.0}/PKG-INFO +1 -1
  2. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/UF/ClassToDict.py +10 -3
  3. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/UF/DecoratorArchive.py +6 -6
  4. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/UF/GetVariable.py +8 -1
  5. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/UF/HelperFunctions.py +7 -6
  6. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/UF/StringCheck.py +1 -1
  7. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/UF/Trigonometry.py +7 -7
  8. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/UF/Validators/QuantumValidators.py +15 -20
  9. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/UF/Validators/ValidationClasses.py +79 -11
  10. universalfunctions-1.3.0/UF/Validators/__init__.py +58 -0
  11. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/UF/__init__.py +18 -15
  12. {universalfunctions-1.1.1 → universalfunctions-1.3.0/UniversalFunctions.egg-info}/PKG-INFO +1 -1
  13. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/pyproject.toml +1 -1
  14. universalfunctions-1.1.1/UF/Validators/__init__.py +0 -16
  15. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/LICENSE +0 -0
  16. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/README.md +0 -0
  17. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/UF/Validators/QuantumFuncValidators.py +0 -0
  18. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/UniversalFunctions.egg-info/SOURCES.txt +0 -0
  19. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/UniversalFunctions.egg-info/dependency_links.txt +0 -0
  20. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/UniversalFunctions.egg-info/top_level.txt +0 -0
  21. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/setup.cfg +0 -0
  22. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/tests/__init__.py +0 -0
  23. {universalfunctions-1.1.1 → universalfunctions-1.3.0}/tests/test_ClassToDict.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: UniversalFunctions
3
- Version: 1.1.1
3
+ Version: 1.3.0
4
4
  Summary: A Python utility library providing foundational functions, validators, and infrastructure.
5
5
  Author-email: "Miah M. Sabiq" <miah.sabiq@gibs.at>
6
6
  Requires-Python: >=3.14
@@ -3,17 +3,24 @@ This module contains a function that takes all functions in a class and make a d
3
3
  """
4
4
 
5
5
  from collections.abc import Callable
6
- from .Validators.QuantumFuncValidators import qtm_validation_decorator
6
+ from .Validators import SequenceValidate
7
7
 
8
8
 
9
- @qtm_validation_decorator
10
- def classes_to_dict(*classes: tuple[type, ...]) -> dict[str, Callable]:
9
+ def classes_to_dict(*classes: type) -> dict[str, Callable]:
11
10
  """
12
11
  Extracts callable objects from the given classes and returns them
13
12
  as a dictionary mapping their names to the corresponding objects
13
+
14
+ >>> class RandomClass:
15
+ ... def get_item(self):
16
+ ... pass
17
+ >>> result = classes_to_dict(RandomClass)
18
+ >>> list(result)
19
+ ['get_item']
14
20
  :param classes: Classes from which the callables are extracted
15
21
  :return: Dictionary of callable names and their objects
16
22
  """
23
+ SequenceValidate(type, ...)(classes, name="classes")
17
24
  dictionary = {}
18
25
  for cls in classes:
19
26
  dictionary.update({
@@ -3,16 +3,16 @@ This module contains decorators which take any number of decorators and apply th
3
3
  """
4
4
 
5
5
  from collections.abc import Callable
6
- from .Validators.QuantumFuncValidators import qtm_validation_decorator
6
+ from .Validators import SequenceValidate
7
7
 
8
8
 
9
- @qtm_validation_decorator
10
- def cls_deco_superposition(*decorators: tuple[Callable, ...]) -> Callable:
9
+ def cls_deco_superposition(*decorators: Callable) -> Callable:
11
10
  """
12
11
  DECORATOR!! Creates a class decorator that applies the given decorator to every user defined function
13
- :param decorator: provided decorator function
12
+ :param decorators: provided decorator functions
14
13
  :return: a class decorator that transforms the class (& it's functions) and returns it
15
14
  """
15
+ SequenceValidate(Callable, ...)(decorators, name="decorators")
16
16
  deco_composer = deco_superposition(*decorators)
17
17
 
18
18
  def inner(cls):
@@ -22,13 +22,13 @@ def cls_deco_superposition(*decorators: tuple[Callable, ...]) -> Callable:
22
22
  return cls
23
23
  return inner
24
24
 
25
- @qtm_validation_decorator
26
- def deco_superposition(*decorators: tuple[Callable, ...]) -> Callable:
25
+ def deco_superposition(*decorators: Callable) -> Callable:
27
26
  """
28
27
  DECORATOR! this decorator takes multiple decorators and applies them to the given function the same way python would naturally
29
28
  :param decorators: decorator functions
30
29
  :return: supplied function
31
30
  """
31
+ SequenceValidate(Callable, ...)(decorators, name="decorators")
32
32
  def inner_deco(func):
33
33
  for decorator in reversed(decorators):
34
34
  func = decorator(func)
@@ -5,7 +5,14 @@ This module contains an extremely important function: get_num, which takes a num
5
5
  from time import sleep as rest
6
6
  from typing import overload, Literal
7
7
  from numbers import Real
8
- from .Validators.ValidationClasses import LessThan, str_validate, real_validate, TypeValidate, GreaterOrEqual, LessOrEqual
8
+ from .Validators import (
9
+ LessThan,
10
+ str_validate,
11
+ real_validate,
12
+ TypeValidate,
13
+ GreaterOrEqual,
14
+ LessOrEqual
15
+ )
9
16
 
10
17
 
11
18
  type int_type = type[int]
@@ -15,14 +15,13 @@ from math import sqrt
15
15
  from .GetVariable import get_num
16
16
  from .DecoratorArchive import cls_deco_superposition
17
17
  from .ClassToDict import classes_to_dict
18
- from .Validators.QuantumFuncValidators import qtm_validation_decorator
19
- from .Validators.ValidationClasses import LessThan, Positive
18
+ from .Validators import qtm_validation_decorator, LessThan, Positive
20
19
  from numbers import Real
21
20
 
22
21
 
23
22
  @cls_deco_superposition(staticmethod)
24
23
  class HelperFunctions:
25
-
24
+ """This class provides a collection of reusable helper functions"""
26
25
  def intervals_f() -> Real:
27
26
  """Asks the user for rational intervals"""
28
27
  interval_num: float = get_num(float, "Enter intervals(ℚ>0): ", MIN=0)
@@ -64,8 +63,6 @@ class HelperFunctions:
64
63
  Calculates the diameter of a square with given length
65
64
  :return: diameter, diameter/2
66
65
  """
67
- if length <= 0:
68
- raise ValueError("Length must be greater than 0")
69
66
 
70
67
  diameter: float = length*sqrt(2); d_half: Real = diameter / 2
71
68
  return diameter, d_half
@@ -90,7 +87,11 @@ class HelperFunctions:
90
87
  helper = HelperFunctions
91
88
 
92
89
  @qtm_validation_decorator
93
- def range_f(start: Real, stop: Real, step: Annotated[Real, Positive()]) -> Generator[Real,Any,None]:
90
+ def range_f(
91
+ start: Real,
92
+ stop: Real,
93
+ step: Annotated[Real, Positive()]
94
+ ) -> Generator[Real,Any,None]:
94
95
  """
95
96
  Lets the user choose Real inputs for start, stop and step
96
97
  :param start: start value; Real number
@@ -3,7 +3,7 @@ This module contains an extremely important function: get_str, which takes a str
3
3
  """
4
4
 
5
5
  from time import sleep as rest
6
- from .Validators.ValidationClasses import TypeValidate, str_validate
6
+ from .Validators import TypeValidate, str_validate
7
7
 
8
8
 
9
9
  def get_str(str_input: str, *check_values) -> str:
@@ -6,32 +6,32 @@ from math import (
6
6
  asin,
7
7
  )
8
8
  from numbers import Real
9
- from .Validators.QuantumFuncValidators import qtm_validation_decorator
9
+ from .Validators import real_validate
10
10
 
11
11
 
12
- @qtm_validation_decorator
13
12
  def sine(angle: Real) -> Real:
14
13
  """
15
14
  Calculates the sine of a given angle
16
15
  :param angle: value required in degrees
17
16
  :return: sine value
18
17
  """
18
+ real_validate()(angle, name="angle")
19
19
  return sin(radians(angle))
20
20
 
21
- @qtm_validation_decorator
22
21
  def cosine(angle: Real) -> Real:
23
22
  """
24
23
  Calculates the cosine of a given angle
25
24
  :param angle: value required in degrees
26
25
  :return: cosine value
27
26
  """
27
+ real_validate()(angle, name="angle")
28
28
  return cos(radians(angle))
29
29
 
30
- @qtm_validation_decorator
31
- def asine(angle: Real) -> Real:
30
+ def asine(value: Real) -> Real:
32
31
  """
33
32
  Calculates the asine of a given angle
34
- :param angle: real value
33
+ :param value: real value
35
34
  :return: asine value
36
35
  """
37
- return degrees(asin(angle))
36
+ real_validate()(value, name="value")
37
+ return degrees(asin(value))
@@ -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) -> bool:
8
+ def qtm_lt_validator(value: list[Any] | tuple[Any, ...], TYPE: Any, name: str) -> tuple | list:
9
9
  """
10
- Takes a list of ONE specific element and validates its contents against the expected type
11
- :param value: list of elements
12
- :param TYPE: list[expected type]
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: True if the contents of value satisfy the expected type
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
- if origin is list:
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 True
29
+ return validator(value, name=name)
36
30
 
37
- def qtm_constr_validator(value, annotation, name) -> bool:
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 True
51
+ return value
@@ -6,7 +6,18 @@ from collections.abc import Callable
6
6
 
7
7
 
8
8
  class TypeValidate:
9
- """Makes sure the entered value is of correct type"""
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
- """Makes sure the entered value is an integer with TypeValidate"""
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
- """Makes sure the entered value is a string with TypeValidate"""
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
- """Makes sure the entered value is a real number with TypeValidate"""
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
- """Makes sure the entered value is positive"""
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 included)"""
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
- """Makes sure the entered value is less than expected value"""
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
- """Makes sure the entered value is less than or equal to expected value"""
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
- """Makes sure the entered value is greater than expected value"""
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
- """Makes sure the entered value is greater than or equal to expected value"""
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
- """Makes sure the entered value is a sequence of any value"""
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:
@@ -0,0 +1,58 @@
1
+ """
2
+ Welcome to the Quantum/Classical Dimension!
3
+
4
+ Here you will find some of the most sensitive pieces of code, however you may gladly use the validators,
5
+ no matter quantum or classic.
6
+ But whatever you do, DO NOT change the actual functions, otherwise, the entire
7
+ software will cease to function.
8
+ Almost every single other module in this software relies on the quantum validation centers, if anything is changed
9
+ inappropriately, the user shall face serious consequences.
10
+
11
+ Abbreviations:
12
+ qtm = Quantum Turtle Mechanics
13
+ ctm = Classical Turtle Mechanics
14
+
15
+ All functions with qtm belong to the Quantum Dimension whereas all functions with ctm belong to the Classical Dimension
16
+ """
17
+
18
+ from .QuantumFuncValidators import qtm_validation_decorator, qtm_func_validator
19
+ from .QuantumValidators import qtm_lt_validator, qtm_constr_validator
20
+ from .ValidationClasses import (
21
+ TypeValidate,
22
+ int_validate,
23
+ str_validate,
24
+ real_validate,
25
+ Positive,
26
+ LessThan,
27
+ LessOrEqual,
28
+ GreaterThan,
29
+ GreaterOrEqual,
30
+ SequenceValidate,
31
+ RealValidationParent,
32
+ )
33
+
34
+ from . import QuantumFuncValidators
35
+ from . import QuantumValidators
36
+ from . import ValidationClasses
37
+
38
+ __all__ = [
39
+ "qtm_validation_decorator",
40
+ "qtm_func_validator",
41
+ "qtm_lt_validator",
42
+ "qtm_constr_validator",
43
+ "TypeValidate",
44
+ "int_validate",
45
+ "str_validate",
46
+ "real_validate",
47
+ "Positive",
48
+ "LessThan",
49
+ "LessOrEqual",
50
+ "GreaterThan",
51
+ "GreaterOrEqual",
52
+ "SequenceValidate",
53
+ "RealValidationParent",
54
+
55
+ "QuantumFuncValidators",
56
+ "QuantumValidators",
57
+ "ValidationClasses",
58
+ ]
@@ -28,20 +28,15 @@ from .HelperFunctions import (
28
28
  )
29
29
  from .StringCheck import get_str
30
30
  from .Trigonometry import sine, cosine, asine
31
- from .Validators.ValidationClasses import (
32
- TypeValidate,
33
- Positive,
34
- int_validate,
35
- str_validate,
36
- real_validate,
37
- LessThan,
38
- LessOrEqual,
39
- GreaterThan,
40
- GreaterOrEqual,
41
- SequenceValidate,
42
- )
43
- from .Validators.QuantumFuncValidators import qtm_validation_decorator, qtm_func_validator
44
- from .Validators.QuantumValidators import qtm_constr_validator, qtm_lt_validator
31
+ from .Validators import *
32
+
33
+ from . import ClassToDict
34
+ from . import DecoratorArchive
35
+ from . import GetVariable
36
+ from . import HelperFunctions as HelperFunctionsModule
37
+ from . import StringCheck
38
+ from . import Trigonometry
39
+ from . import Validators
45
40
 
46
41
  __all__ = [
47
42
  "classes_to_dict",
@@ -68,5 +63,13 @@ __all__ = [
68
63
  "qtm_validation_decorator",
69
64
  "qtm_func_validator",
70
65
  "qtm_constr_validator",
71
- "qtm_lt_validator"
66
+ "qtm_lt_validator",
67
+
68
+ "ClassToDict",
69
+ "DecoratorArchive",
70
+ "GetVariable",
71
+ "HelperFunctionsModule",
72
+ "StringCheck",
73
+ "Trigonometry",
74
+ "Validators",
72
75
  ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: UniversalFunctions
3
- Version: 1.1.1
3
+ Version: 1.3.0
4
4
  Summary: A Python utility library providing foundational functions, validators, and infrastructure.
5
5
  Author-email: "Miah M. Sabiq" <miah.sabiq@gibs.at>
6
6
  Requires-Python: >=3.14
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "UniversalFunctions"
7
- version = "1.1.1"
7
+ version = "1.3.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"
@@ -1,16 +0,0 @@
1
- """
2
- Welcome to the Quantum/Classical Dimension!
3
-
4
- Here you will find some of the most sensitive pieces of code, however you may gladly use the validators,
5
- no matter quantum or classic.
6
- But whatever you do, DO NOT change the actual functions, otherwise, the entire
7
- software will cease to function.
8
- Almost every single other module in this software relies on the quantum validation centers, if anything is changed
9
- inappropriately, the user shall face serious consequences.
10
-
11
- Abbreviations:
12
- qtm = Quantum Turtle Mechanics
13
- ctm = Classical Turtle Mechanics
14
-
15
- All functions with qtm belong to the Quantum Dimension whereas all functions with ctm belong to the Classical Dimension
16
- """