UniversalFunctions 1.3.0__tar.gz → 2.0.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 (26) hide show
  1. {universalfunctions-1.3.0/UniversalFunctions.egg-info → universalfunctions-2.0.0}/PKG-INFO +22 -22
  2. {universalfunctions-1.3.0 → universalfunctions-2.0.0}/README.md +21 -21
  3. universalfunctions-2.0.0/UF/GetVariable.py +116 -0
  4. {universalfunctions-1.3.0 → universalfunctions-2.0.0}/UF/Trigonometry.py +4 -0
  5. universalfunctions-2.0.0/UF/Validators/Errors.py +103 -0
  6. {universalfunctions-1.3.0 → universalfunctions-2.0.0}/UF/Validators/QuantumFuncValidators.py +5 -5
  7. {universalfunctions-1.3.0 → universalfunctions-2.0.0}/UF/Validators/QuantumValidators.py +20 -3
  8. universalfunctions-2.0.0/UF/Validators/ValidationClasses.py +406 -0
  9. {universalfunctions-1.3.0 → universalfunctions-2.0.0}/UF/Validators/__init__.py +19 -0
  10. {universalfunctions-1.3.0 → universalfunctions-2.0.0}/UF/__init__.py +17 -5
  11. {universalfunctions-1.3.0 → universalfunctions-2.0.0/UniversalFunctions.egg-info}/PKG-INFO +22 -22
  12. {universalfunctions-1.3.0 → universalfunctions-2.0.0}/UniversalFunctions.egg-info/SOURCES.txt +1 -1
  13. universalfunctions-2.0.0/UniversalFunctions.egg-info/top_level.txt +1 -0
  14. {universalfunctions-1.3.0 → universalfunctions-2.0.0}/pyproject.toml +1 -2
  15. universalfunctions-1.3.0/UF/GetVariable.py +0 -91
  16. universalfunctions-1.3.0/UF/Validators/ValidationClasses.py +0 -230
  17. universalfunctions-1.3.0/UniversalFunctions.egg-info/top_level.txt +0 -2
  18. universalfunctions-1.3.0/tests/__init__.py +0 -0
  19. {universalfunctions-1.3.0 → universalfunctions-2.0.0}/LICENSE +0 -0
  20. {universalfunctions-1.3.0 → universalfunctions-2.0.0}/UF/ClassToDict.py +0 -0
  21. {universalfunctions-1.3.0 → universalfunctions-2.0.0}/UF/DecoratorArchive.py +0 -0
  22. {universalfunctions-1.3.0 → universalfunctions-2.0.0}/UF/HelperFunctions.py +0 -0
  23. {universalfunctions-1.3.0 → universalfunctions-2.0.0}/UF/StringCheck.py +0 -0
  24. {universalfunctions-1.3.0 → universalfunctions-2.0.0}/UniversalFunctions.egg-info/dependency_links.txt +0 -0
  25. {universalfunctions-1.3.0 → universalfunctions-2.0.0}/setup.cfg +0 -0
  26. {universalfunctions-1.3.0 → universalfunctions-2.0.0}/tests/test_ClassToDict.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: UniversalFunctions
3
- Version: 1.3.0
3
+ Version: 2.0.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
@@ -28,10 +28,12 @@ The package requires Python 3.14 or later.
28
28
 
29
29
  UniversalFunctions is imported through the UF Python package:
30
30
 
31
+ ```python
31
32
  from UF.Validators import TypeValidate
32
33
  from numbers import Real
33
34
 
34
35
  TypeValidate(Real)(56)
36
+ ```
35
37
 
36
38
  The distribution name is UniversalFunctions, while the Python import package is UF.
37
39
 
@@ -49,16 +51,25 @@ Provides runtime validation utilities and validation classes for enforcing types
49
51
 
50
52
  #### Notable components include:
51
53
 
52
- * ``TypeValidate``
53
- * ``TupleValidate``
54
- * ``LessThan``
55
- * ``LessOrEqual``
56
- * ``GreaterOrEqual``
57
- * ``Positive``
58
- * ``real_validate``
59
- * ``str_validate``
54
+ * ``TypeValidate`` -> class for validating an object against an expected type
55
+ * ``SequenceValidate`` -> class used to validate a sequence of objects
56
+ * ``LessThan`` -> class to validate a real number, constraint: value < expected
57
+ * ``qtm_validation_decorator`` -> when applied to a function, the decorator takes the provided parameter values and validates them against the expected type
58
+ * ``ErrorDedent``
60
59
  * Callable validation utilities
61
60
 
61
+ This package inside UF contains numerous validators designed to validate all sorts of values and types,
62
+ including some sophisticated ones like SequenceValidate which allows users to enter extra restrictions to the items in a given sequence.
63
+
64
+ There are 2 extra errors which are provided:
65
+ * ``ItemCountError``
66
+ * ``ConstraintError``
67
+
68
+ ItemCountError was created since Python does not have an error for a situation where the values and types
69
+ might be correct, though the number of items is not.
70
+
71
+ ConstraintError provides users to express that the type of a value might be correct, though it fails to pass a specific constraint.
72
+
62
73
  The validation system also contains the Quantum Turtle Mechanics (QTM) validation infrastructure used for more structured runtime validation.
63
74
 
64
75
  ### Decorators
@@ -67,9 +78,8 @@ UniversalFunctions provides reusable decorator infrastructure, including decorat
67
78
 
68
79
  #### Notable components include:
69
80
 
70
- * ``class_decorator``
71
- * ``deco_superposition``
72
- * ``cls_deco_superposition``
81
+ * ``deco_superposition`` -> applies an arbitrary number of decorators to a function
82
+ * ``cls_deco_superposition`` -> applies an arbitrary number of decorators to every function in a class, except for protected ones (names starting with "_")
73
83
  * Quantum Turtle Mechanics validation decorators
74
84
 
75
85
  ### Helper Functions
@@ -106,16 +116,6 @@ Python 3.14 or later
106
116
 
107
117
  UniversalFunctions is designed for modern Python and makes use of contemporary Python typing and language features.
108
118
 
109
- ## Development
110
-
111
- Clone the repository and install it in editable mode:
112
-
113
- git clone https://github.com/Mangosaber2026/UniversalFunctions.git
114
- cd UniversalFunctions
115
- pip install -e .
116
-
117
- Editable installation allows changes to the source code to be reflected immediately without reinstalling the package.
118
-
119
119
  ## License
120
120
 
121
121
  UniversalFunctions is distributed under the terms of the license included in this repository.
@@ -18,10 +18,12 @@ The package requires Python 3.14 or later.
18
18
 
19
19
  UniversalFunctions is imported through the UF Python package:
20
20
 
21
+ ```python
21
22
  from UF.Validators import TypeValidate
22
23
  from numbers import Real
23
24
 
24
25
  TypeValidate(Real)(56)
26
+ ```
25
27
 
26
28
  The distribution name is UniversalFunctions, while the Python import package is UF.
27
29
 
@@ -39,16 +41,25 @@ Provides runtime validation utilities and validation classes for enforcing types
39
41
 
40
42
  #### Notable components include:
41
43
 
42
- * ``TypeValidate``
43
- * ``TupleValidate``
44
- * ``LessThan``
45
- * ``LessOrEqual``
46
- * ``GreaterOrEqual``
47
- * ``Positive``
48
- * ``real_validate``
49
- * ``str_validate``
44
+ * ``TypeValidate`` -> class for validating an object against an expected type
45
+ * ``SequenceValidate`` -> class used to validate a sequence of objects
46
+ * ``LessThan`` -> class to validate a real number, constraint: value < expected
47
+ * ``qtm_validation_decorator`` -> when applied to a function, the decorator takes the provided parameter values and validates them against the expected type
48
+ * ``ErrorDedent``
50
49
  * Callable validation utilities
51
50
 
51
+ This package inside UF contains numerous validators designed to validate all sorts of values and types,
52
+ including some sophisticated ones like SequenceValidate which allows users to enter extra restrictions to the items in a given sequence.
53
+
54
+ There are 2 extra errors which are provided:
55
+ * ``ItemCountError``
56
+ * ``ConstraintError``
57
+
58
+ ItemCountError was created since Python does not have an error for a situation where the values and types
59
+ might be correct, though the number of items is not.
60
+
61
+ ConstraintError provides users to express that the type of a value might be correct, though it fails to pass a specific constraint.
62
+
52
63
  The validation system also contains the Quantum Turtle Mechanics (QTM) validation infrastructure used for more structured runtime validation.
53
64
 
54
65
  ### Decorators
@@ -57,9 +68,8 @@ UniversalFunctions provides reusable decorator infrastructure, including decorat
57
68
 
58
69
  #### Notable components include:
59
70
 
60
- * ``class_decorator``
61
- * ``deco_superposition``
62
- * ``cls_deco_superposition``
71
+ * ``deco_superposition`` -> applies an arbitrary number of decorators to a function
72
+ * ``cls_deco_superposition`` -> applies an arbitrary number of decorators to every function in a class, except for protected ones (names starting with "_")
63
73
  * Quantum Turtle Mechanics validation decorators
64
74
 
65
75
  ### Helper Functions
@@ -96,16 +106,6 @@ Python 3.14 or later
96
106
 
97
107
  UniversalFunctions is designed for modern Python and makes use of contemporary Python typing and language features.
98
108
 
99
- ## Development
100
-
101
- Clone the repository and install it in editable mode:
102
-
103
- git clone https://github.com/Mangosaber2026/UniversalFunctions.git
104
- cd UniversalFunctions
105
- pip install -e .
106
-
107
- Editable installation allows changes to the source code to be reflected immediately without reinstalling the package.
108
-
109
109
  ## License
110
110
 
111
111
  UniversalFunctions is distributed under the terms of the license included in this repository.
@@ -0,0 +1,116 @@
1
+ """
2
+ This module contains an extremely important function: get_num, which takes a numerical value from the user.
3
+ """
4
+
5
+ from time import sleep as rest
6
+ from typing import overload, Literal, Final
7
+ from numbers import Real
8
+ from .Validators import (
9
+ LessThan,
10
+ str_validate,
11
+ real_validate,
12
+ TypeValidate,
13
+ GreaterOrEqual,
14
+ LessOrEqual,
15
+ type_error,
16
+ GreaterThan,
17
+ )
18
+
19
+
20
+ type int_type = type[int]
21
+ type float_type = type[float]
22
+
23
+ @overload
24
+ def get_num(TYPE: int_type, entry: str, **options) -> int: ...
25
+
26
+ @overload
27
+ def get_num(TYPE: float_type, entry: str, **options) -> float: ...
28
+
29
+ def get_num(
30
+ TYPE: float_type|int_type,
31
+ entry: str,
32
+ **options
33
+ ) -> Real:
34
+ """
35
+ Gets a real numerical value from the user
36
+
37
+ :param TYPE: float or int; which type of value to check for
38
+ :param entry: str; input string
39
+ :param options: MAX, MIN, store
40
+ :return: float or int
41
+ """
42
+ func_name: Final[Literal["get_num"]] = "get_num"
43
+ type_obj_name: Final[Literal["TYPE"]] = "TYPE"
44
+
45
+ store_var: Final[Literal["store"]] = "store"
46
+ store_value = options[store_var]
47
+
48
+ min_var: Final[Literal["MIN"]] = "MIN"
49
+ min_value = options[min_var]
50
+
51
+ max_var: Final[Literal["MAX"]] = "MAX"
52
+ max_value = options[max_var]
53
+
54
+ if TYPE not in (int, float):
55
+ raise type_error()(f"""
56
+ TypeError
57
+
58
+ Function: {func_name}
59
+ Parameter {type_obj_name} must be type float or int!
60
+ Expected: int or float object
61
+ Received:
62
+ Name: {type_obj_name}
63
+ Value: {TYPE}
64
+ """)
65
+
66
+ str_validate()(entry, name="entry")
67
+
68
+ real_validate()(max_value, name=max_var)
69
+ real_validate()(min_value, name=min_var)
70
+
71
+ if min_var in options and max_var in options:
72
+ LessThan(max_value)(min_value, name=min_var)
73
+
74
+ if store_var in options:
75
+ TypeValidate((Real, type(None)))(store_value, name=store_var)
76
+
77
+ if (
78
+ store_var in options
79
+ and min_var in options
80
+ and max_var in options
81
+ and store_value is not None
82
+ ):
83
+ GreaterThan(min_value)(store_value, name=store_var)
84
+
85
+ while True:
86
+ try:
87
+ if store_var in options:
88
+ reserve: str = input(entry)
89
+ if reserve == "ans":
90
+ if isinstance(store_value, Real):
91
+ value: Real = store_value
92
+ else:
93
+ print("\nThere is no value stored yet!")
94
+ continue
95
+ else:
96
+ value: Real = TYPE(reserve)
97
+ else:
98
+ value: Real = TYPE(input(entry))
99
+ value_name: Literal["value"] = "value"
100
+
101
+ if min_var in options and max_var in options:
102
+ GreaterOrEqual(min_value)(value, name=value_name)
103
+ LessOrEqual(max_value)(value, name=value_name)
104
+
105
+ elif min_var in options:
106
+ GreaterOrEqual(min_value)(value, name=value_name)
107
+
108
+ elif max_var in options:
109
+ LessOrEqual(max_value)(value, name=value_name)
110
+
111
+ elif store_var in options:
112
+ options["store"] = value
113
+ return value
114
+ except ValueError as error:
115
+ print(error)
116
+ rest(1.5)
@@ -1,3 +1,7 @@
1
+ """
2
+ This module contains a collection of trigonometric functions to be used with degrees.
3
+ """
4
+
1
5
  from math import (
2
6
  radians,
3
7
  degrees,
@@ -0,0 +1,103 @@
1
+ """
2
+ This module provides a collection of error message deliverers and separate errors created by the author which
3
+ are not normally provided with Python.
4
+
5
+ The custom errors in this module can be used just like any other conventional error provided by Python itself.
6
+ """
7
+
8
+ from textwrap import dedent
9
+ from typing import Callable, Final, Literal
10
+
11
+
12
+ class ErrorDedent:
13
+ """
14
+ This class is the error raiser for the other validators found in this package (UF).
15
+
16
+ The use of this class is to make the error message be printed with some formatting instead of the conventional
17
+ way it would be printed otherwise.
18
+
19
+ >>> print(ErrorDedent(TypeError)("This is a TypeError!"))
20
+ This is a TypeError!
21
+ """
22
+ name: Final[Literal["ErrorDedent"]] = "ErrorDedent"
23
+ def __init__(self, error_func) -> None:
24
+ if not isinstance(error_func, type) or not issubclass(error_func, Exception):
25
+ raise TypeError(dedent(f"""
26
+ TypeError:
27
+ Validator: ErrorDedent
28
+ Parameter 'error_func' MUST be an error class!
29
+ expected: Exception subclass
30
+ received: {error_func}
31
+ """).strip())
32
+ self.error_func = error_func
33
+
34
+ def __call__(self, text: str) -> Exception:
35
+ if not isinstance(text, str):
36
+ raise TypeError(dedent(f"""
37
+ TypeError:
38
+ Validator: {self.name}
39
+ Parameter 'text' MUST be a string object!
40
+ expected: str
41
+ received: {text}
42
+ """).strip())
43
+ return self.error_func(dedent(text).strip())
44
+
45
+ def type_error() -> Callable:
46
+ """
47
+ This function returns a callable type error function.
48
+
49
+ >>> print(type_error()("This is a TypeError!"))
50
+ This is a TypeError!
51
+
52
+ :return: ErrorDedent function
53
+ """
54
+ return ErrorDedent(TypeError)
55
+
56
+ def value_error() -> Callable:
57
+ """
58
+ This function returns a callable value error function.
59
+
60
+ >>> print(value_error()("This is a ValueError!"))
61
+ This is a ValueError!
62
+
63
+ :return: ErrorDedent function
64
+ """
65
+ return ErrorDedent(ValueError)
66
+
67
+ def item_count_error() -> Callable:
68
+ """
69
+ This function returns a callable item count error function.
70
+
71
+ >>> print(item_count_error()("This is an Item Count Error!"))
72
+ This is an Item Count Error!
73
+
74
+ :return: ErrorDedent function
75
+ """
76
+ return ErrorDedent(ItemCountError)
77
+
78
+ def constraint_error() -> Callable:
79
+ """
80
+ This function returns a callable constraint error function.
81
+
82
+ >>> print(constraint_error()("This is a Constraint Error!"))
83
+ This is a Constraint Error!
84
+
85
+ :return: ErrorDedent function
86
+ """
87
+ return ErrorDedent(ConstraintError)
88
+
89
+ class ItemCountError(Exception):
90
+ """
91
+ This exception is raised when an item count does not match the expected count.
92
+
93
+ >>> print(ItemCountError("This is an Item Count Error!"))
94
+ This is an Item Count Error!
95
+ """
96
+
97
+ class ConstraintError(Exception):
98
+ """
99
+ This exception is raised when an item does not pass the expected constraint.
100
+
101
+ >>> print(ConstraintError("This is a Constraint Error!"))
102
+ This is a Constraint Error!
103
+ """
@@ -10,13 +10,13 @@ from functools import wraps
10
10
  from .ValidationClasses import TypeValidate
11
11
 
12
12
 
13
- def qtm_func_validator(func: Callable, *args, **kwargs) -> bool:
13
+ def qtm_func_validator(func: Callable, *args, **kwargs) -> Callable:
14
14
  """
15
15
  Takes a function and compares the entered value with the expected type
16
16
  :param func: given function
17
17
  :param args: arguments
18
18
  :param kwargs: keyword arguments
19
- :return: True if the provided argument matches the expected type, raises an error if not
19
+ :return: given function if the provided argument matches the expected type, raises an error if not
20
20
  """
21
21
  TypeValidate(Callable)(func, name=func.__name__)
22
22
  sig = signature(func)
@@ -40,11 +40,11 @@ def qtm_func_validator(func: Callable, *args, **kwargs) -> bool:
40
40
  else:
41
41
  TypeValidate(type_)(value, name=name)
42
42
 
43
- return True
43
+ return func
44
44
 
45
45
  def qtm_validation_decorator(func: Callable) -> Callable:
46
46
  """
47
- DECORATOR!
47
+ QUANTUM DECORATOR!
48
48
 
49
49
  Decorates a function with the quantum function validator and returns the function
50
50
  :param func: provided function
@@ -56,4 +56,4 @@ def qtm_validation_decorator(func: Callable) -> Callable:
56
56
  def wrapper(*args, **kwargs):
57
57
  qtm_func_validator(func, *args, **kwargs)
58
58
  return func(*args, **kwargs)
59
- return wrapper
59
+ return wrapper
@@ -4,6 +4,8 @@ This module contains type validators for list and tuple which belong to the QTM
4
4
 
5
5
  from typing import Any, get_args, get_origin, Annotated
6
6
  from .ValidationClasses import TypeValidate, SequenceValidate
7
+ from .Errors import type_error
8
+ from typing import Final, Literal
7
9
 
8
10
  def qtm_lt_validator(value: list[Any] | tuple[Any, ...], TYPE: Any, name: str) -> tuple | list:
9
11
  """
@@ -17,9 +19,17 @@ def qtm_lt_validator(value: list[Any] | tuple[Any, ...], TYPE: Any, name: str) -
17
19
  :param name: name of value
18
20
  :return: validated list/tuple of elements
19
21
  """
22
+ func_name: Final[Literal["qtm_lt_validator"]] = "qtm_lt_validator"
20
23
  origin = get_origin(TYPE)
21
24
  if origin not in (list, tuple):
22
- raise TypeError(f"{TYPE} must be a list or tuple for a specific type! e.g. list[int]")
25
+ raise type_error()(f"""
26
+ TypeError
27
+
28
+ Validator: {func_name}
29
+ Parameter TYPE must be a list/tuple of elements!
30
+ Expected: type object
31
+ Received: {TYPE}
32
+ """)
23
33
 
24
34
  TypeValidate(origin)(value)
25
35
 
@@ -36,9 +46,16 @@ def qtm_constr_validator(value: Any, annotation, name: str) -> Any:
36
46
  :param name: name of value
37
47
  :return: True, if validation succeeds
38
48
  """
39
-
49
+ func_name: Final[Literal["qtm_constr_validator"]] = "qtm_constr_validator"
40
50
  if get_origin(annotation) is not Annotated:
41
- raise TypeError(f"{annotation} is not an Annotated type!")
51
+ raise type_error()(f"""
52
+ TypeError
53
+
54
+ Validator: {func_name}
55
+ Parameter annotation is not an Annotated type!
56
+ Expected: Annotated object
57
+ Received: {annotation}
58
+ """)
42
59
 
43
60
  type_obj, *constraints = get_args(annotation)
44
61