orionis 0.233.0__py3-none-any.whl → 0.235.0__py3-none-any.whl
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.
- orionis/framework.py +1 -1
- orionis/luminate/support/introspection/__init__.py +7 -0
- orionis/luminate/support/introspection/dependencies/contracts/reflect_dependencies.py +43 -0
- orionis/luminate/support/introspection/dependencies/entities/__init__.py +0 -0
- orionis/luminate/support/introspection/dependencies/entities/class_dependencies.py +10 -0
- orionis/luminate/support/introspection/dependencies/entities/method_dependencies.py +10 -0
- orionis/luminate/support/introspection/dependencies/entities/resolved_dependencies.py +12 -0
- orionis/luminate/support/introspection/dependencies/reflect_dependencies.py +176 -0
- orionis/luminate/support/introspection/helpers/__init__.py +0 -0
- orionis/luminate/support/introspection/helpers/functions.py +281 -0
- orionis/luminate/support/{inspection/reflexion_abstract.py → introspection/reflect_abstract.py} +1 -1
- orionis/luminate/support/introspection/reflect_decorators.py +335 -0
- orionis/luminate/support/{inspection → introspection}/reflection.py +21 -27
- orionis/luminate/support/introspection/reflection_instance.py +801 -0
- orionis/luminate/support/{inspection → introspection}/reflexion_concrete_with_abstract.py +2 -2
- orionis/luminate/support/{inspection → introspection}/reflexion_instance_with_abstract.py +4 -4
- orionis/luminate/test/__init__.py +13 -0
- orionis/luminate/test/cases/__init__.py +0 -0
- orionis/luminate/test/cases/test_async.py +32 -0
- orionis/luminate/test/cases/test_case.py +23 -0
- orionis/luminate/test/cases/test_sync.py +10 -0
- orionis/luminate/test/core/__init__.py +0 -0
- orionis/luminate/test/core/contracts/__init__.py +0 -0
- orionis/luminate/test/{test_suite.py → core/test_suite.py} +2 -2
- orionis/luminate/test/{test_unit.py → core/test_unit.py} +4 -4
- orionis/luminate/test/entities/__init__.py +0 -0
- orionis/luminate/test/{test_result.py → entities/test_result.py} +2 -2
- orionis/luminate/test/enums/__init__.py +0 -0
- orionis/luminate/test/exceptions/__init__.py +0 -0
- orionis/luminate/test/output/__init__.py +0 -0
- orionis/luminate/test/{test_std_out.py → output/test_std_out.py} +1 -1
- {orionis-0.233.0.dist-info → orionis-0.235.0.dist-info}/METADATA +1 -1
- {orionis-0.233.0.dist-info → orionis-0.235.0.dist-info}/RECORD +64 -52
- tests/example/test_example.py +1 -1
- tests/support/adapters/test_doct_dict.py +1 -1
- tests/support/async_io/test_async_coroutine.py +1 -1
- tests/support/environment/test_env.py +1 -1
- tests/support/inspection/test_reflection_abstract.py +20 -2
- tests/support/inspection/test_reflection_concrete.py +3 -3
- tests/support/inspection/test_reflection_concrete_with_abstract.py +2 -2
- tests/support/inspection/test_reflection_instance.py +41 -17
- tests/support/inspection/test_reflection_instance_with_abstract.py +2 -2
- tests/support/parsers/test_exception_parser.py +1 -1
- tests/support/path/test_resolver.py +6 -6
- tests/support/patterns/test_singleton.py +1 -1
- tests/support/standard/test_std.py +1 -1
- orionis/luminate/support/inspection/functions.py +0 -263
- orionis/luminate/support/inspection/reflexion_instance.py +0 -580
- orionis/luminate/test/test_case.py +0 -62
- orionis/static/favicon/OrionisFrameworkFavicon.png +0 -0
- orionis/static/logos/OrionisFramework.jpg +0 -0
- orionis/static/logos/OrionisFramework.png +0 -0
- orionis/static/logos/OrionisFramework.psd +0 -0
- orionis/static/logos/OrionisFramework2.png +0 -0
- orionis/static/logos/OrionisFramework3.png +0 -0
- /orionis/luminate/support/{inspection → introspection}/container_integrity.py +0 -0
- /orionis/luminate/support/{inspection → introspection/contracts}/__init__.py +0 -0
- /orionis/luminate/support/{inspection → introspection}/contracts/reflection.py +0 -0
- /orionis/luminate/support/{inspection → introspection}/contracts/reflexion_abstract.py +0 -0
- /orionis/luminate/support/{inspection/contracts → introspection/dependencies}/__init__.py +0 -0
- /orionis/luminate/{test → support/introspection/dependencies}/contracts/__init__.py +0 -0
- /orionis/luminate/support/{inspection → introspection}/reflexion_concrete.py +0 -0
- /orionis/luminate/support/{inspection → introspection}/reflexion_module.py +0 -0
- /orionis/luminate/support/{inspection → introspection}/reflexion_module_with_classname.py +0 -0
- /orionis/luminate/test/{contracts → core/contracts}/test_suite.py +0 -0
- /orionis/luminate/test/{contracts → core/contracts}/test_unit.py +0 -0
- /orionis/luminate/test/{test_status.py → enums/test_status.py} +0 -0
- /orionis/luminate/test/{test_exception.py → exceptions/test_exception.py} +0 -0
- /orionis/luminate/test/{contracts → output/contracts}/test_std_out.py +0 -0
- {orionis-0.233.0.dist-info → orionis-0.235.0.dist-info}/LICENCE +0 -0
- {orionis-0.233.0.dist-info → orionis-0.235.0.dist-info}/WHEEL +0 -0
- {orionis-0.233.0.dist-info → orionis-0.235.0.dist-info}/entry_points.txt +0 -0
- {orionis-0.233.0.dist-info → orionis-0.235.0.dist-info}/top_level.txt +0 -0
orionis/framework.py
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
from orionis.luminate.support.introspection.dependencies.entities.class_dependencies import ClassDependency
|
3
|
+
from orionis.luminate.support.introspection.dependencies.entities.method_dependencies import MethodDependency
|
4
|
+
|
5
|
+
class IReflectDependencies(ABC):
|
6
|
+
"""
|
7
|
+
This class is used to reflect dependencies of a given object.
|
8
|
+
"""
|
9
|
+
|
10
|
+
def __init__(self, obj):
|
11
|
+
self.__obj = obj
|
12
|
+
|
13
|
+
@abstractmethod
|
14
|
+
def getConstructorDependencies(self) -> ClassDependency:
|
15
|
+
"""
|
16
|
+
Get the resolved and unresolved dependencies from the constructor of the instance's class.
|
17
|
+
|
18
|
+
Returns
|
19
|
+
-------
|
20
|
+
ClassDependency
|
21
|
+
A structured representation of the constructor dependencies, containing:
|
22
|
+
- resolved: Dictionary of resolved dependencies with their names and values.
|
23
|
+
- unresolved: List of unresolved dependencies (parameter names without default values or annotations).
|
24
|
+
"""
|
25
|
+
pass
|
26
|
+
|
27
|
+
def getMethodDependencies(self, method_name: str) -> MethodDependency:
|
28
|
+
"""
|
29
|
+
Get the resolved and unresolved dependencies from a method of the instance's class.
|
30
|
+
|
31
|
+
Parameters
|
32
|
+
----------
|
33
|
+
method_name : str
|
34
|
+
The name of the method to inspect
|
35
|
+
|
36
|
+
Returns
|
37
|
+
-------
|
38
|
+
MethodDependency
|
39
|
+
A structured representation of the method dependencies, containing:
|
40
|
+
- resolved: Dictionary of resolved dependencies with their names and values.
|
41
|
+
- unresolved: List of unresolved dependencies (parameter names without default values or annotations).
|
42
|
+
"""
|
43
|
+
pass
|
File without changes
|
@@ -0,0 +1,12 @@
|
|
1
|
+
from dataclasses import dataclass
|
2
|
+
from typing import Type
|
3
|
+
|
4
|
+
@dataclass(frozen=True)
|
5
|
+
class ResolvedDependency:
|
6
|
+
"""
|
7
|
+
A class to represent a resolved dependency of a class instance.
|
8
|
+
"""
|
9
|
+
module_name: str
|
10
|
+
class_name: str
|
11
|
+
type: Type
|
12
|
+
full_class_path: str
|
@@ -0,0 +1,176 @@
|
|
1
|
+
import inspect
|
2
|
+
from typing import Any, Dict, List
|
3
|
+
from orionis.luminate.support.introspection.dependencies.contracts.reflect_dependencies import IReflectDependencies
|
4
|
+
from orionis.luminate.support.introspection.dependencies.entities.class_dependencies import ClassDependency
|
5
|
+
from orionis.luminate.support.introspection.dependencies.entities.method_dependencies import MethodDependency
|
6
|
+
from orionis.luminate.support.introspection.dependencies.entities.resolved_dependencies import ResolvedDependency
|
7
|
+
|
8
|
+
class ReflectDependencies(IReflectDependencies):
|
9
|
+
"""
|
10
|
+
This class is used to reflect dependencies of a given object.
|
11
|
+
"""
|
12
|
+
|
13
|
+
def __init__(self, obj):
|
14
|
+
"""
|
15
|
+
Initializes the ReflectDependencies instance with the given object.
|
16
|
+
|
17
|
+
Parameters
|
18
|
+
----------
|
19
|
+
obj : Any
|
20
|
+
The object whose dependencies are to be reflected.
|
21
|
+
"""
|
22
|
+
self.__obj = obj
|
23
|
+
|
24
|
+
def __paramSkip(self, param_name: str, param: inspect.Parameter) -> bool:
|
25
|
+
"""
|
26
|
+
Determines whether a parameter should be skipped during dependency inspection.
|
27
|
+
|
28
|
+
Parameters
|
29
|
+
----------
|
30
|
+
param_name : str
|
31
|
+
The name of the parameter.
|
32
|
+
param : inspect.Parameter
|
33
|
+
The parameter object to inspect.
|
34
|
+
|
35
|
+
Returns
|
36
|
+
-------
|
37
|
+
bool
|
38
|
+
True if the parameter should be skipped, False otherwise.
|
39
|
+
"""
|
40
|
+
# Skip common parameters like 'self', 'cls', or special argument names
|
41
|
+
if param_name in {'self', 'cls', 'args', 'kwargs'}:
|
42
|
+
return True
|
43
|
+
|
44
|
+
# Skip 'self' in class methods or instance methods
|
45
|
+
if param_name == 'self' and isinstance(self.__obj, type):
|
46
|
+
return True
|
47
|
+
|
48
|
+
# Skip special parameters like *args and **kwargs
|
49
|
+
if param.kind in {param.VAR_POSITIONAL, param.VAR_KEYWORD}:
|
50
|
+
return True
|
51
|
+
|
52
|
+
return False
|
53
|
+
|
54
|
+
def __inspectSignature(self, target) -> inspect.Signature:
|
55
|
+
"""
|
56
|
+
Safely retrieves the signature of a given target.
|
57
|
+
|
58
|
+
Parameters
|
59
|
+
----------
|
60
|
+
target : Any
|
61
|
+
The target object (function, method, or callable) to inspect.
|
62
|
+
|
63
|
+
Returns
|
64
|
+
-------
|
65
|
+
inspect.Signature
|
66
|
+
The signature of the target.
|
67
|
+
|
68
|
+
Raises
|
69
|
+
------
|
70
|
+
ValueError
|
71
|
+
If the signature cannot be inspected.
|
72
|
+
"""
|
73
|
+
if not callable(target):
|
74
|
+
raise ValueError(f"Target {target} is not callable and cannot have a signature.")
|
75
|
+
|
76
|
+
try:
|
77
|
+
return inspect.signature(target)
|
78
|
+
except (ValueError, TypeError) as e:
|
79
|
+
raise ValueError(f"Unable to inspect signature of {target}: {str(e)}")
|
80
|
+
|
81
|
+
def getConstructorDependencies(self) -> ClassDependency:
|
82
|
+
"""
|
83
|
+
Get the resolved and unresolved dependencies from the constructor of the instance's class.
|
84
|
+
|
85
|
+
Returns
|
86
|
+
-------
|
87
|
+
ClassDependency
|
88
|
+
A structured representation of the constructor dependencies, containing:
|
89
|
+
- resolved: Dictionary of resolved dependencies with their names and values.
|
90
|
+
- unresolved: List of unresolved dependencies (parameter names without default values or annotations).
|
91
|
+
"""
|
92
|
+
signature = self.__inspectSignature(self.__obj.__init__)
|
93
|
+
resolved_dependencies: Dict[str, Any] = {}
|
94
|
+
unresolved_dependencies: List[str] = []
|
95
|
+
|
96
|
+
for param_name, param in signature.parameters.items():
|
97
|
+
|
98
|
+
# Skip parameters that are not relevant for dependency resolution
|
99
|
+
if self.__paramSkip(param_name, param):
|
100
|
+
continue
|
101
|
+
|
102
|
+
# Add to the list of unresolved dependencies if it has no default value or annotation
|
103
|
+
if param.annotation is param.empty and param.default is param.empty:
|
104
|
+
unresolved_dependencies.append(param_name)
|
105
|
+
continue
|
106
|
+
|
107
|
+
# Parameters with default values
|
108
|
+
if param.default is not param.empty:
|
109
|
+
resolved_dependencies[param_name] = param.default
|
110
|
+
continue
|
111
|
+
|
112
|
+
# If the parameter has an annotation, it is added to the list of resolved dependencies
|
113
|
+
if param.annotation is not param.empty:
|
114
|
+
module_path = param.annotation.__module__
|
115
|
+
resolved_dependencies[param_name] = ResolvedDependency(
|
116
|
+
module_name=module_path,
|
117
|
+
class_name=param.annotation.__name__,
|
118
|
+
type=param.annotation,
|
119
|
+
full_class_path=f"{module_path}.{param.annotation.__name__}"
|
120
|
+
)
|
121
|
+
|
122
|
+
return ClassDependency(
|
123
|
+
resolved=resolved_dependencies,
|
124
|
+
unresolved=unresolved_dependencies
|
125
|
+
)
|
126
|
+
|
127
|
+
def getMethodDependencies(self, method_name: str) -> MethodDependency:
|
128
|
+
"""
|
129
|
+
Get the resolved and unresolved dependencies from a method of the instance's class.
|
130
|
+
|
131
|
+
Parameters
|
132
|
+
----------
|
133
|
+
method_name : str
|
134
|
+
The name of the method to inspect
|
135
|
+
|
136
|
+
Returns
|
137
|
+
-------
|
138
|
+
MethodDependency
|
139
|
+
A structured representation of the method dependencies, containing:
|
140
|
+
- resolved: Dictionary of resolved dependencies with their names and values.
|
141
|
+
- unresolved: List of unresolved dependencies (parameter names without default values or annotations).
|
142
|
+
"""
|
143
|
+
signature = self.__inspectSignature(getattr(self.__obj, method_name))
|
144
|
+
resolved_dependencies: Dict[str, Any] = {}
|
145
|
+
unresolved_dependencies: List[str] = []
|
146
|
+
|
147
|
+
for param_name, param in signature.parameters.items():
|
148
|
+
|
149
|
+
# Skip parameters that are not relevant for dependency resolution
|
150
|
+
if self.__paramSkip(param_name, param):
|
151
|
+
continue
|
152
|
+
|
153
|
+
# Add to the list of unresolved dependencies if it has no default value or annotation
|
154
|
+
if param.annotation is param.empty and param.default is param.empty:
|
155
|
+
unresolved_dependencies.append(param_name)
|
156
|
+
continue
|
157
|
+
|
158
|
+
# Parameters with default values
|
159
|
+
if param.default is not param.empty:
|
160
|
+
resolved_dependencies[param_name] = param.default
|
161
|
+
continue
|
162
|
+
|
163
|
+
# If the parameter has an annotation, it is added to the list of resolved dependencies
|
164
|
+
if param.annotation is not param.empty:
|
165
|
+
module_path = param.annotation.__module__
|
166
|
+
resolved_dependencies[param_name] = ResolvedDependency(
|
167
|
+
module_name=module_path,
|
168
|
+
class_name=param.annotation.__name__,
|
169
|
+
type=param.annotation,
|
170
|
+
full_class_path=f"{module_path}.{param.annotation.__name__}"
|
171
|
+
)
|
172
|
+
|
173
|
+
return MethodDependency(
|
174
|
+
resolved=resolved_dependencies,
|
175
|
+
unresolved=unresolved_dependencies
|
176
|
+
)
|
File without changes
|
@@ -0,0 +1,281 @@
|
|
1
|
+
from typing import Any, Type
|
2
|
+
import inspect
|
3
|
+
import importlib
|
4
|
+
|
5
|
+
class HelpersReflection:
|
6
|
+
"""
|
7
|
+
A collection of helper functions for reflection and inspection.
|
8
|
+
"""
|
9
|
+
|
10
|
+
@staticmethod
|
11
|
+
def isValidModule(module_name: str) -> bool:
|
12
|
+
"""Check if a module name is valid and can be imported.
|
13
|
+
|
14
|
+
Parameters
|
15
|
+
----------
|
16
|
+
module_name : str
|
17
|
+
The name of the module to check
|
18
|
+
|
19
|
+
Returns
|
20
|
+
-------
|
21
|
+
bool
|
22
|
+
True if the module is valid and can be imported, False otherwise
|
23
|
+
"""
|
24
|
+
try:
|
25
|
+
importlib.import_module(module_name)
|
26
|
+
return True
|
27
|
+
except ImportError:
|
28
|
+
return False
|
29
|
+
|
30
|
+
@staticmethod
|
31
|
+
def ensureValidModule(module_name: str) -> None:
|
32
|
+
"""Ensure a module name is valid and can be imported.
|
33
|
+
|
34
|
+
Parameters
|
35
|
+
----------
|
36
|
+
module_name : str
|
37
|
+
The name of the module to check
|
38
|
+
|
39
|
+
Raises
|
40
|
+
------
|
41
|
+
ValueError
|
42
|
+
If the module cannot be imported or is invalid
|
43
|
+
"""
|
44
|
+
if not isinstance(module_name, str):
|
45
|
+
raise TypeError(f"Module name must be a string, got {type(module_name)}")
|
46
|
+
if not HelpersReflection.isValidModule(module_name):
|
47
|
+
raise ValueError(f"Invalid or non-importable module: {module_name}")
|
48
|
+
|
49
|
+
@staticmethod
|
50
|
+
def isInstantiableClass(cls: Type) -> bool:
|
51
|
+
"""Check if a class is concrete and can be instantiated.
|
52
|
+
|
53
|
+
Parameters
|
54
|
+
----------
|
55
|
+
cls : Type
|
56
|
+
The class to check
|
57
|
+
|
58
|
+
Returns
|
59
|
+
--
|
60
|
+
bool
|
61
|
+
True if the class is concrete and can be instantiated, False otherwise
|
62
|
+
"""
|
63
|
+
if not isinstance(cls, type):
|
64
|
+
return False
|
65
|
+
if HelpersReflection.isAbstractClass(cls):
|
66
|
+
return False
|
67
|
+
try:
|
68
|
+
# Try to create an instance to verify it's truly concrete
|
69
|
+
cls()
|
70
|
+
return True
|
71
|
+
except TypeError:
|
72
|
+
return False
|
73
|
+
|
74
|
+
@staticmethod
|
75
|
+
def ensureNotBuiltinType(cls: Type) -> None:
|
76
|
+
"""Ensure a class is not a built-in or primitive type.
|
77
|
+
|
78
|
+
Parameters
|
79
|
+
----------
|
80
|
+
cls : Type
|
81
|
+
The class to check
|
82
|
+
|
83
|
+
Raises
|
84
|
+
------
|
85
|
+
TypeError
|
86
|
+
If the input is not a class
|
87
|
+
ValueError
|
88
|
+
If the class is a built-in or primitive type
|
89
|
+
"""
|
90
|
+
if not isinstance(cls, type):
|
91
|
+
raise TypeError(f"Expected a class, got {type(cls)}")
|
92
|
+
|
93
|
+
builtin_types = {
|
94
|
+
int, float, str, bool, bytes, type(None), complex,
|
95
|
+
list, tuple, dict, set, frozenset
|
96
|
+
}
|
97
|
+
|
98
|
+
if cls in builtin_types:
|
99
|
+
raise ValueError(f"Class '{cls.__name__}' is a built-in or primitive type and cannot be used.")
|
100
|
+
|
101
|
+
@staticmethod
|
102
|
+
def ensureInstantiableClass(cls: Type) -> None:
|
103
|
+
"""Ensure a class is concrete and can be instantiated.
|
104
|
+
|
105
|
+
Parameters
|
106
|
+
----------
|
107
|
+
cls : Type
|
108
|
+
The class to check
|
109
|
+
|
110
|
+
Raises
|
111
|
+
------
|
112
|
+
TypeError
|
113
|
+
If the input is not a class
|
114
|
+
ValueError
|
115
|
+
If the class is abstract or cannot be instantiated
|
116
|
+
"""
|
117
|
+
if HelpersReflection.ensureNotBuiltinType(cls):
|
118
|
+
raise TypeError(f"Invalid class: {cls!r}")
|
119
|
+
if not isinstance(cls, type):
|
120
|
+
raise TypeError(f"Expected a class, got {type(cls)}")
|
121
|
+
if HelpersReflection.isAbstractClass(cls):
|
122
|
+
raise ValueError(f"Class '{cls.__name__}' is abstract")
|
123
|
+
try:
|
124
|
+
cls()
|
125
|
+
except TypeError as e:
|
126
|
+
raise ValueError(f"Class '{cls.__name__}' cannot be instantiated: {str(e)}")
|
127
|
+
|
128
|
+
@staticmethod
|
129
|
+
def isValidClassName(module_name: str, class_name: str) -> bool:
|
130
|
+
"""Check if a class exists in a given module.
|
131
|
+
|
132
|
+
Parameters
|
133
|
+
----------
|
134
|
+
module_name : str
|
135
|
+
The name of the module to check
|
136
|
+
class_name : str
|
137
|
+
The name of the class to look for
|
138
|
+
|
139
|
+
Returns
|
140
|
+
-------
|
141
|
+
bool
|
142
|
+
True if the class exists in the module, False otherwise
|
143
|
+
"""
|
144
|
+
try:
|
145
|
+
module = importlib.import_module(module_name)
|
146
|
+
return hasattr(module, class_name) and inspect.isclass(getattr(module, class_name))
|
147
|
+
except ImportError:
|
148
|
+
return False
|
149
|
+
|
150
|
+
@staticmethod
|
151
|
+
def ensureValidClassName(module_name: str, class_name: str) -> None:
|
152
|
+
"""Ensure a class exists in a given module.
|
153
|
+
|
154
|
+
Parameters
|
155
|
+
----------
|
156
|
+
module_name : str
|
157
|
+
The name of the module to check
|
158
|
+
class_name : str
|
159
|
+
The name of the class to look for
|
160
|
+
|
161
|
+
Raises
|
162
|
+
------
|
163
|
+
ValueError
|
164
|
+
If the class doesn't exist in the module
|
165
|
+
"""
|
166
|
+
if not HelpersReflection.isValidClassName(module_name, class_name):
|
167
|
+
raise ValueError(f"Class '{class_name}' not found in module '{module_name}'")
|
168
|
+
|
169
|
+
@staticmethod
|
170
|
+
def isUserDefinedClassInstance(instance: Any) -> bool:
|
171
|
+
"""Check if an object is an instance of a user-defined class.
|
172
|
+
|
173
|
+
Parameters
|
174
|
+
----------
|
175
|
+
instance : Any
|
176
|
+
The object to check
|
177
|
+
|
178
|
+
Returns
|
179
|
+
-------
|
180
|
+
bool
|
181
|
+
True if the object is an instance of a user-defined class, False otherwise
|
182
|
+
"""
|
183
|
+
return isinstance(instance, object) and type(instance).__module__ not in {'builtins', 'abc', '__main__'}
|
184
|
+
|
185
|
+
@staticmethod
|
186
|
+
def ensureUserDefinedClassInstance(instance: Any) -> None:
|
187
|
+
"""Ensure an object is an instance of a user-defined class.
|
188
|
+
|
189
|
+
Parameters
|
190
|
+
----------
|
191
|
+
instance : Any
|
192
|
+
The object to check
|
193
|
+
|
194
|
+
Raises
|
195
|
+
------
|
196
|
+
TypeError
|
197
|
+
If the input is not an object instance
|
198
|
+
ValueError
|
199
|
+
If the instance is from builtins, abc, or __main__
|
200
|
+
"""
|
201
|
+
if not isinstance(instance, object):
|
202
|
+
raise TypeError(f"Invalid object: {instance!r}")
|
203
|
+
module = type(instance).__module__
|
204
|
+
if module in {'builtins', 'abc'}:
|
205
|
+
raise ValueError(f"'{instance!r}' is not a user-defined class instance, belongs to '{module}'.")
|
206
|
+
if module == '__main__':
|
207
|
+
raise ValueError("Instance originates from '__main__', origin indeterminate.")
|
208
|
+
|
209
|
+
@staticmethod
|
210
|
+
def isAbstractClass(cls: Type) -> bool:
|
211
|
+
"""Check if a class is abstract.
|
212
|
+
|
213
|
+
Parameters
|
214
|
+
----------
|
215
|
+
cls : Type
|
216
|
+
The class to check
|
217
|
+
|
218
|
+
Returns
|
219
|
+
-------
|
220
|
+
bool
|
221
|
+
True if the class is abstract, False otherwise
|
222
|
+
"""
|
223
|
+
return isinstance(cls, type) and bool(getattr(cls, '__abstractmethods__', False))
|
224
|
+
|
225
|
+
@staticmethod
|
226
|
+
def ensureAbstractClass(cls: Type) -> None:
|
227
|
+
"""Ensure a class is abstract.
|
228
|
+
|
229
|
+
Parameters
|
230
|
+
----------
|
231
|
+
cls : Type
|
232
|
+
The class to check
|
233
|
+
|
234
|
+
Raises
|
235
|
+
------
|
236
|
+
TypeError
|
237
|
+
If the input is not a class
|
238
|
+
ValueError
|
239
|
+
If the class is not abstract
|
240
|
+
"""
|
241
|
+
if not isinstance(cls, type):
|
242
|
+
raise TypeError(f"Invalid class: {cls!r}")
|
243
|
+
if not HelpersReflection.isAbstractClass(cls):
|
244
|
+
raise ValueError(f"Class '{cls.__name__}' is not abstract.")
|
245
|
+
|
246
|
+
@staticmethod
|
247
|
+
def isConcreteClass(cls: Type) -> bool:
|
248
|
+
"""Check if a class is concrete.
|
249
|
+
|
250
|
+
Parameters
|
251
|
+
----------
|
252
|
+
cls : Type
|
253
|
+
The class to check
|
254
|
+
|
255
|
+
Returns
|
256
|
+
-------
|
257
|
+
bool
|
258
|
+
True if the class is concrete, False otherwise
|
259
|
+
"""
|
260
|
+
return isinstance(cls, type) and not HelpersReflection.isAbstractClass(cls)
|
261
|
+
|
262
|
+
@staticmethod
|
263
|
+
def ensureConcreteClass(cls: Type) -> None:
|
264
|
+
"""Ensure a class is concrete.
|
265
|
+
|
266
|
+
Parameters
|
267
|
+
----------
|
268
|
+
cls : Type
|
269
|
+
The class to check
|
270
|
+
|
271
|
+
Raises
|
272
|
+
------
|
273
|
+
TypeError
|
274
|
+
If the input is not a class
|
275
|
+
ValueError
|
276
|
+
If the class is not concrete
|
277
|
+
"""
|
278
|
+
if not isinstance(cls, type):
|
279
|
+
raise TypeError(f"Invalid class: {cls!r}")
|
280
|
+
if not HelpersReflection.isConcreteClass(cls):
|
281
|
+
raise ValueError(f"Class '{cls.__name__}' is not concrete.")
|
orionis/luminate/support/{inspection/reflexion_abstract.py → introspection/reflect_abstract.py}
RENAMED
@@ -3,7 +3,7 @@ import ast
|
|
3
3
|
import inspect
|
4
4
|
import types
|
5
5
|
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, TypeVar
|
6
|
-
from orionis.luminate.support.
|
6
|
+
from orionis.luminate.support.introspection.contracts.reflexion_abstract import IReflexionAbstract
|
7
7
|
|
8
8
|
ABC = TypeVar('ABC', bound=abc.ABC)
|
9
9
|
|