UniversalFunctions 1.3.0__tar.gz → 2.1.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.1.0}/PKG-INFO +22 -22
  2. {universalfunctions-1.3.0 → universalfunctions-2.1.0}/README.md +21 -21
  3. {universalfunctions-1.3.0 → universalfunctions-2.1.0}/UF/ClassToDict.py +1 -0
  4. universalfunctions-2.1.0/UF/GetVariable.py +116 -0
  5. {universalfunctions-1.3.0 → universalfunctions-2.1.0}/UF/Trigonometry.py +16 -0
  6. universalfunctions-2.1.0/UF/Validators/Errors.py +130 -0
  7. {universalfunctions-1.3.0 → universalfunctions-2.1.0}/UF/Validators/QuantumFuncValidators.py +5 -5
  8. {universalfunctions-1.3.0 → universalfunctions-2.1.0}/UF/Validators/QuantumValidators.py +16 -3
  9. universalfunctions-2.1.0/UF/Validators/ValidationClasses.py +379 -0
  10. {universalfunctions-1.3.0 → universalfunctions-2.1.0}/UF/Validators/__init__.py +19 -0
  11. {universalfunctions-1.3.0 → universalfunctions-2.1.0}/UF/__init__.py +17 -5
  12. {universalfunctions-1.3.0 → universalfunctions-2.1.0/UniversalFunctions.egg-info}/PKG-INFO +22 -22
  13. {universalfunctions-1.3.0 → universalfunctions-2.1.0}/UniversalFunctions.egg-info/SOURCES.txt +1 -1
  14. universalfunctions-2.1.0/UniversalFunctions.egg-info/top_level.txt +1 -0
  15. {universalfunctions-1.3.0 → universalfunctions-2.1.0}/pyproject.toml +1 -2
  16. universalfunctions-1.3.0/UF/GetVariable.py +0 -91
  17. universalfunctions-1.3.0/UF/Validators/ValidationClasses.py +0 -230
  18. universalfunctions-1.3.0/UniversalFunctions.egg-info/top_level.txt +0 -2
  19. universalfunctions-1.3.0/tests/__init__.py +0 -0
  20. {universalfunctions-1.3.0 → universalfunctions-2.1.0}/LICENSE +0 -0
  21. {universalfunctions-1.3.0 → universalfunctions-2.1.0}/UF/DecoratorArchive.py +0 -0
  22. {universalfunctions-1.3.0 → universalfunctions-2.1.0}/UF/HelperFunctions.py +0 -0
  23. {universalfunctions-1.3.0 → universalfunctions-2.1.0}/UF/StringCheck.py +0 -0
  24. {universalfunctions-1.3.0 → universalfunctions-2.1.0}/UniversalFunctions.egg-info/dependency_links.txt +0 -0
  25. {universalfunctions-1.3.0 → universalfunctions-2.1.0}/setup.cfg +0 -0
  26. {universalfunctions-1.3.0 → universalfunctions-2.1.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.1.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.
@@ -17,6 +17,7 @@ def classes_to_dict(*classes: type) -> dict[str, Callable]:
17
17
  >>> result = classes_to_dict(RandomClass)
18
18
  >>> list(result)
19
19
  ['get_item']
20
+
20
21
  :param classes: Classes from which the callables are extracted
21
22
  :return: Dictionary of callable names and their objects
22
23
  """
@@ -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,
@@ -12,6 +16,10 @@ from .Validators import real_validate
12
16
  def sine(angle: Real) -> Real:
13
17
  """
14
18
  Calculates the sine of a given angle
19
+
20
+ >>> sin(0)
21
+ 0
22
+
15
23
  :param angle: value required in degrees
16
24
  :return: sine value
17
25
  """
@@ -21,6 +29,10 @@ def sine(angle: Real) -> Real:
21
29
  def cosine(angle: Real) -> Real:
22
30
  """
23
31
  Calculates the cosine of a given angle
32
+
33
+ >>> cosine(0)
34
+ 1
35
+
24
36
  :param angle: value required in degrees
25
37
  :return: cosine value
26
38
  """
@@ -30,6 +42,10 @@ def cosine(angle: Real) -> Real:
30
42
  def asine(value: Real) -> Real:
31
43
  """
32
44
  Calculates the asine of a given angle
45
+
46
+ >>> asine(0)
47
+ 0
48
+
33
49
  :param value: real value
34
50
  :return: asine value
35
51
  """
@@ -0,0 +1,130 @@
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
+ TypeError
21
+ <BLANKLINE>
22
+ This is a TypeError!
23
+ """
24
+ name: Final[Literal["ErrorDedent"]] = "ErrorDedent"
25
+ def __init__(self, error_func) -> None:
26
+ if not isinstance(error_func, type) or not issubclass(error_func, Exception):
27
+ raise TypeError(dedent(f"""
28
+ TypeError:
29
+ Validator: ErrorDedent
30
+ Parameter 'error_func' MUST be an error class!
31
+ expected: Exception subclass
32
+ received: {error_func}
33
+ """).strip())
34
+ self.error_func = error_func
35
+
36
+ def __call__(self, text: str) -> Exception:
37
+ if not isinstance(text, str):
38
+ raise TypeError(dedent(f"""
39
+ TypeError:
40
+ Validator: {self.name}
41
+ Parameter 'text' MUST be a string object!
42
+ expected: str
43
+ received: {text}
44
+ """).strip())
45
+ return self.error_func(dedent(f"""
46
+ {self.error_func.__name__}
47
+
48
+ {text}
49
+ """).strip())
50
+
51
+ def type_error() -> Callable:
52
+ """
53
+ This function returns a callable type error function.
54
+
55
+ >>> print(type_error()("This is a TypeError!"))
56
+ TypeError
57
+ <BLANKLINE>
58
+ This is a TypeError!
59
+
60
+ :return: ErrorDedent function
61
+ """
62
+ return ErrorDedent(TypeError)
63
+
64
+ def value_error() -> Callable:
65
+ """
66
+ This function returns a callable value error function.
67
+
68
+ >>> print(value_error()("This is a ValueError!"))
69
+ ValueError
70
+ <BLANKLINE>
71
+ This is a ValueError!
72
+
73
+ :return: ErrorDedent function
74
+ """
75
+ return ErrorDedent(ValueError)
76
+
77
+ def item_count_error() -> Callable:
78
+ """
79
+ This function returns a callable item count error function.
80
+
81
+ >>> print(item_count_error()("This is an Item Count Error!"))
82
+ ItemCountError
83
+ <BLANKLINE>
84
+ This is an Item Count Error!
85
+
86
+ :return: ErrorDedent function
87
+ """
88
+ return ErrorDedent(ItemCountError)
89
+
90
+ def constraint_error() -> Callable:
91
+ """
92
+ This function returns a callable constraint error function.
93
+
94
+ >>> print(constraint_error()("This is a Constraint Error!"))
95
+ ConstraintError
96
+ <BLANKLINE>
97
+ This is a Constraint Error!
98
+
99
+ :return: ErrorDedent function
100
+ """
101
+ return ErrorDedent(ConstraintError)
102
+
103
+ def attribute_error() -> Callable:
104
+ """
105
+ This function returns a callable attribute error function.
106
+
107
+ >>> print(attribute_error()("This is an Attribute Error!"))
108
+ AttributeError
109
+ <BLANKLINE>
110
+ This is an Attribute Error!
111
+
112
+ :return: ErrorDedent function
113
+ """
114
+ return ErrorDedent(AttributeError)
115
+
116
+ class ItemCountError(Exception):
117
+ """
118
+ This exception is raised when an item count does not match the expected count.
119
+
120
+ >>> print(ItemCountError("This is an Item Count Error!"))
121
+ This is an Item Count Error!
122
+ """
123
+
124
+ class ConstraintError(Exception):
125
+ """
126
+ This exception is raised when an item does not pass the expected constraint.
127
+
128
+ >>> print(ConstraintError("This is a Constraint Error!"))
129
+ This is a Constraint Error!
130
+ """
@@ -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,15 @@ 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
+ Validator: {func_name}
27
+ Parameter TYPE must be a list/tuple of elements!
28
+ Expected: type object
29
+ Received: {TYPE}
30
+ """)
23
31
 
24
32
  TypeValidate(origin)(value)
25
33
 
@@ -36,9 +44,14 @@ def qtm_constr_validator(value: Any, annotation, name: str) -> Any:
36
44
  :param name: name of value
37
45
  :return: True, if validation succeeds
38
46
  """
39
-
47
+ func_name: Final[Literal["qtm_constr_validator"]] = "qtm_constr_validator"
40
48
  if get_origin(annotation) is not Annotated:
41
- raise TypeError(f"{annotation} is not an Annotated type!")
49
+ raise type_error()(f"""
50
+ Validator: {func_name}
51
+ Parameter annotation is not an Annotated type!
52
+ Expected: Annotated object
53
+ Received: {annotation}
54
+ """)
42
55
 
43
56
  type_obj, *constraints = get_args(annotation)
44
57