orionis 0.210.0__py3-none-any.whl → 0.213.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 CHANGED
@@ -5,7 +5,7 @@
5
5
  NAME = "orionis"
6
6
 
7
7
  # Current version of the framework
8
- VERSION = "0.210.0"
8
+ VERSION = "0.213.0"
9
9
 
10
10
  # Full name of the author or maintainer of the project
11
11
  AUTHOR = "Raul Mauricio Uñate Castro"
@@ -2,7 +2,7 @@ from typing import Any, Type
2
2
  import inspect
3
3
  import importlib
4
4
 
5
- def is_valid_module(module_name: str) -> bool:
5
+ def _is_valid_module(module_name: str) -> bool:
6
6
  """Check if a module name is valid and can be imported.
7
7
 
8
8
  Parameters
@@ -21,7 +21,7 @@ def is_valid_module(module_name: str) -> bool:
21
21
  except ImportError:
22
22
  return False
23
23
 
24
- def ensure_valid_module(module_name: str) -> None:
24
+ def _ensure_valid_module(module_name: str) -> None:
25
25
  """Ensure a module name is valid and can be imported.
26
26
 
27
27
  Parameters
@@ -36,10 +36,10 @@ def ensure_valid_module(module_name: str) -> None:
36
36
  """
37
37
  if not isinstance(module_name, str):
38
38
  raise TypeError(f"Module name must be a string, got {type(module_name)}")
39
- if not is_valid_module(module_name):
39
+ if not _is_valid_module(module_name):
40
40
  raise ValueError(f"Invalid or non-importable module: {module_name}")
41
41
 
42
- def is_instantiable_class(cls: Type) -> bool:
42
+ def _is_instantiable_class(cls: Type) -> bool:
43
43
  """Check if a class is concrete and can be instantiated.
44
44
 
45
45
  Parameters
@@ -54,7 +54,7 @@ def is_instantiable_class(cls: Type) -> bool:
54
54
  """
55
55
  if not isinstance(cls, type):
56
56
  return False
57
- if is_abstract_class(cls):
57
+ if _is_abstract_class(cls):
58
58
  return False
59
59
  try:
60
60
  # Try to create an instance to verify it's truly concrete
@@ -63,7 +63,33 @@ def is_instantiable_class(cls: Type) -> bool:
63
63
  except TypeError:
64
64
  return False
65
65
 
66
- def ensure_instantiable_class(cls: Type) -> None:
66
+ def _ensure_not_builtin_type(cls: Type) -> None:
67
+ """Ensure a class is not a built-in or primitive type.
68
+
69
+ Parameters
70
+ ----------
71
+ cls : Type
72
+ The class to check
73
+
74
+ Raises
75
+ ------
76
+ TypeError
77
+ If the input is not a class
78
+ ValueError
79
+ If the class is a built-in or primitive type
80
+ """
81
+ if not isinstance(cls, type):
82
+ raise TypeError(f"Expected a class, got {type(cls)}")
83
+
84
+ builtin_types = {
85
+ int, float, str, bool, bytes, type(None), complex,
86
+ list, tuple, dict, set, frozenset
87
+ }
88
+
89
+ if cls in builtin_types:
90
+ raise ValueError(f"Class '{cls.__name__}' is a built-in or primitive type and cannot be used.")
91
+
92
+ def _ensure_instantiable_class(cls: Type) -> None:
67
93
  """Ensure a class is concrete and can be instantiated.
68
94
 
69
95
  Parameters
@@ -78,16 +104,18 @@ def ensure_instantiable_class(cls: Type) -> None:
78
104
  ValueError
79
105
  If the class is abstract or cannot be instantiated
80
106
  """
107
+ if _ensure_not_builtin_type(cls):
108
+ raise TypeError(f"Invalid class: {cls!r}")
81
109
  if not isinstance(cls, type):
82
110
  raise TypeError(f"Expected a class, got {type(cls)}")
83
- if is_abstract_class(cls):
111
+ if _is_abstract_class(cls):
84
112
  raise ValueError(f"Class '{cls.__name__}' is abstract")
85
113
  try:
86
114
  cls()
87
115
  except TypeError as e:
88
116
  raise ValueError(f"Class '{cls.__name__}' cannot be instantiated: {str(e)}")
89
117
 
90
- def is_valid_class_name(module_name: str, class_name: str) -> bool:
118
+ def _is_valid_class_name(module_name: str, class_name: str) -> bool:
91
119
  """Check if a class exists in a given module.
92
120
 
93
121
  Parameters
@@ -108,7 +136,7 @@ def is_valid_class_name(module_name: str, class_name: str) -> bool:
108
136
  except ImportError:
109
137
  return False
110
138
 
111
- def ensure_valid_class_name(module_name: str, class_name: str) -> None:
139
+ def _ensure_valid_class_name(module_name: str, class_name: str) -> None:
112
140
  """Ensure a class exists in a given module.
113
141
 
114
142
  Parameters
@@ -123,10 +151,10 @@ def ensure_valid_class_name(module_name: str, class_name: str) -> None:
123
151
  ValueError
124
152
  If the class doesn't exist in the module
125
153
  """
126
- if not is_valid_class_name(module_name, class_name):
154
+ if not _is_valid_class_name(module_name, class_name):
127
155
  raise ValueError(f"Class '{class_name}' not found in module '{module_name}'")
128
156
 
129
- def is_user_defined_class_instance(instance: Any) -> bool:
157
+ def _is_user_defined_class_instance(instance: Any) -> bool:
130
158
  """Check if an object is an instance of a user-defined class.
131
159
 
132
160
  Parameters
@@ -141,7 +169,7 @@ def is_user_defined_class_instance(instance: Any) -> bool:
141
169
  """
142
170
  return isinstance(instance, object) and type(instance).__module__ not in {'builtins', 'abc', '__main__'}
143
171
 
144
- def ensure_user_defined_class_instance(instance: Any) -> None:
172
+ def _ensure_user_defined_class_instance(instance: Any) -> None:
145
173
  """Ensure an object is an instance of a user-defined class.
146
174
 
147
175
  Parameters
@@ -164,7 +192,7 @@ def ensure_user_defined_class_instance(instance: Any) -> None:
164
192
  if module == '__main__':
165
193
  raise ValueError("Instance originates from '__main__', origin indeterminate.")
166
194
 
167
- def is_abstract_class(cls: Type) -> bool:
195
+ def _is_abstract_class(cls: Type) -> bool:
168
196
  """Check if a class is abstract.
169
197
 
170
198
  Parameters
@@ -179,7 +207,7 @@ def is_abstract_class(cls: Type) -> bool:
179
207
  """
180
208
  return isinstance(cls, type) and bool(getattr(cls, '__abstractmethods__', False))
181
209
 
182
- def ensure_abstract_class(cls: Type) -> None:
210
+ def _ensure_abstract_class(cls: Type) -> None:
183
211
  """Ensure a class is abstract.
184
212
 
185
213
  Parameters
@@ -196,10 +224,10 @@ def ensure_abstract_class(cls: Type) -> None:
196
224
  """
197
225
  if not isinstance(cls, type):
198
226
  raise TypeError(f"Invalid class: {cls!r}")
199
- if not is_abstract_class(cls):
227
+ if not _is_abstract_class(cls):
200
228
  raise ValueError(f"Class '{cls.__name__}' is not abstract.")
201
229
 
202
- def is_concrete_class(cls: Type) -> bool:
230
+ def _is_concrete_class(cls: Type) -> bool:
203
231
  """Check if a class is concrete.
204
232
 
205
233
  Parameters
@@ -212,9 +240,9 @@ def is_concrete_class(cls: Type) -> bool:
212
240
  bool
213
241
  True if the class is concrete, False otherwise
214
242
  """
215
- return isinstance(cls, type) and not is_abstract_class(cls)
243
+ return isinstance(cls, type) and not _is_abstract_class(cls)
216
244
 
217
- def ensure_concrete_class(cls: Type) -> None:
245
+ def _ensure_concrete_class(cls: Type) -> None:
218
246
  """Ensure a class is concrete.
219
247
 
220
248
  Parameters
@@ -231,5 +259,5 @@ def ensure_concrete_class(cls: Type) -> None:
231
259
  """
232
260
  if not isinstance(cls, type):
233
261
  raise TypeError(f"Invalid class: {cls!r}")
234
- if not is_concrete_class(cls):
262
+ if not _is_concrete_class(cls):
235
263
  raise ValueError(f"Class '{cls.__name__}' is not concrete.")
@@ -1,11 +1,11 @@
1
1
  import abc
2
2
  from typing import Any, Type, TypeVar
3
3
  from orionis.luminate.support.inspection.functions import (
4
- ensure_abstract_class,
5
- ensure_instantiable_class,
6
- ensure_user_defined_class_instance,
7
- ensure_valid_class_name,
8
- ensure_valid_module,
4
+ _ensure_abstract_class,
5
+ _ensure_instantiable_class,
6
+ _ensure_user_defined_class_instance,
7
+ _ensure_valid_class_name,
8
+ _ensure_valid_module,
9
9
  )
10
10
  from orionis.luminate.support.inspection.reflexion_abstract import ReflexionAbstract
11
11
  from orionis.luminate.support.inspection.reflexion_concrete import ReflexionConcrete
@@ -64,7 +64,7 @@ class Reflection:
64
64
  ValueError
65
65
  If the instance is from builtins, abc, or __main__
66
66
  """
67
- ensure_user_defined_class_instance(instance)
67
+ _ensure_user_defined_class_instance(instance)
68
68
  return ReflexionInstance(instance)
69
69
 
70
70
  @staticmethod
@@ -90,8 +90,8 @@ class Reflection:
90
90
  ValueError
91
91
  If the instance is invalid or abstract is not actually abstract
92
92
  """
93
- ensure_user_defined_class_instance(instance)
94
- ensure_abstract_class(abstract)
93
+ _ensure_user_defined_class_instance(instance)
94
+ _ensure_abstract_class(abstract)
95
95
  return ReflexionInstanceWithAbstract(instance, abstract)
96
96
 
97
97
  @staticmethod
@@ -115,7 +115,7 @@ class Reflection:
115
115
  ValueError
116
116
  If the class is not abstract
117
117
  """
118
- ensure_abstract_class(abstract)
118
+ _ensure_abstract_class(abstract)
119
119
  return ReflexionAbstract(abstract)
120
120
 
121
121
  @staticmethod
@@ -139,7 +139,7 @@ class Reflection:
139
139
  ValueError
140
140
  If the class is abstract or cannot be instantiated
141
141
  """
142
- ensure_instantiable_class(concrete)
142
+ _ensure_instantiable_class(concrete)
143
143
  return ReflexionConcrete(concrete)
144
144
 
145
145
  @staticmethod
@@ -165,8 +165,8 @@ class Reflection:
165
165
  ValueError
166
166
  If concrete is not instantiable or abstract is not actually abstract
167
167
  """
168
- ensure_instantiable_class(concrete)
169
- ensure_abstract_class(abstract)
168
+ _ensure_instantiable_class(concrete)
169
+ _ensure_abstract_class(abstract)
170
170
  return ReflexionConcreteWithAbstract(concrete, abstract)
171
171
 
172
172
  @staticmethod
@@ -190,7 +190,7 @@ class Reflection:
190
190
  ValueError
191
191
  If the module cannot be imported
192
192
  """
193
- ensure_valid_module(module)
193
+ _ensure_valid_module(module)
194
194
  return ReflexionModule(module)
195
195
 
196
196
  @staticmethod
@@ -216,434 +216,6 @@ class Reflection:
216
216
  ValueError
217
217
  If the module cannot be imported or the class doesn't exist in it
218
218
  """
219
- ensure_valid_module(module)
220
- ensure_valid_class_name(module, class_name)
221
- return ReflexionModuleWithClassName(module, class_name)
222
-
223
-
224
-
225
-
226
-
227
-
228
-
229
-
230
-
231
-
232
-
233
-
234
-
235
-
236
-
237
-
238
-
239
-
240
-
241
- # def __inidt__(self,
242
- # instance: Any = None, # Instancia ya creada de una clase
243
- # concrete: Callable[..., Any] = None, # Clase concreta a instanciar
244
- # abstract: Callable[..., Any] = None, # Clase abstracta a implementar en clases hijas
245
- # module: str = None, # Módulo donde se encuentra la clase
246
- # class_name: str = None # Nombre de la clase
247
- # ):
248
-
249
- # # Garantizar que al menos un argumento sea proporcionado
250
- # if not any([abstract, concrete, module, class_name]):
251
- # raise ValueError("At least one argument must be provided.")
252
-
253
-
254
- # # Validar que 'abstract' y 'concrete' sean callables
255
- # if abstract and not callable(abstract):
256
- # raise TypeError("The 'abstract' argument must be callable.")
257
- # if concrete and not callable(concrete):
258
- # raise TypeError("The 'concrete' argument must be callable.")
259
-
260
- # # Validar que si se proporciona una clase, también se proporcione el módulo
261
- # if class_name and not module:
262
- # raise ValueError("If a class name is provided, a module name must also be provided.")
263
-
264
- # # Validar que el módulo exista e importarlo
265
- # if module:
266
- # try:
267
- # self._module = importlib.import_module(module)
268
- # except ModuleNotFoundError:
269
- # raise ValueError(f"Module '{module}' not found.")
270
-
271
- # # Validar que la clase exista en el módulo
272
- # if module and class_name:
273
- # if not hasattr(self._module, class_name):
274
- # raise ValueError(f"Class '{class_name}' not found in module '{module}'.")
275
-
276
- # # Validar que la clase no sea abstracta antes de instanciarla
277
- # if concrete and inspect.isabstract(concrete):
278
- # raise TypeError(f"Cannot instantiate abstract class '{concrete.__name__}'.")
279
-
280
-
281
- # def safeImport(self):
282
- # """
283
- # Safely imports the specified module and assigns the class object if a classname is provided.
284
-
285
- # This method raises a ValueError if the module cannot be imported or if the class does not exist
286
- # within the module.
287
-
288
- # Raises
289
- # ------
290
- # ValueError
291
- # If the module cannot be imported or the class does not exist in the module.
292
- # """
293
- # try:
294
- # module = importlib.import_module(self.module_name)
295
- # if self.classname:
296
- # self.cls = getattr(module, self.classname, None)
297
- # if self.cls is None:
298
- # raise ValueError(f"Class '{self.classname}' not found in module '{self.module_name}'.")
299
- # except ImportError as e:
300
- # raise ValueError(f"Error importing module '{self.module_name}': {e}")
301
-
302
-
303
-
304
-
305
-
306
-
307
-
308
-
309
-
310
-
311
-
312
-
313
-
314
-
315
-
316
-
317
-
318
-
319
-
320
-
321
-
322
-
323
-
324
-
325
-
326
-
327
-
328
-
329
-
330
-
331
- # def getFile(self) -> str:
332
- # """
333
- # Retrieves the file path where the class is defined.
334
-
335
- # Returns
336
- # -------
337
- # str
338
- # The file path if the class is found, otherwise raises an error.
339
-
340
- # Raises
341
- # ------
342
- # ValueError
343
- # If the class has not been loaded yet.
344
- # """
345
- # if not self.cls:
346
- # raise ValueError("Class not loaded. Use 'safeImport()' first.")
347
- # return inspect.getfile(self.cls)
348
-
349
- # def hasClass(self) -> bool:
350
- # """
351
- # Checks whether the class object is available.
352
-
353
- # Returns
354
- # -------
355
- # bool
356
- # True if the class is loaded, False otherwise.
357
- # """
358
- # return self.cls is not None
359
-
360
- # def hasMethod(self, method_name: str) -> bool:
361
- # """
362
- # Checks whether the specified method exists in the class.
363
-
364
- # Parameters
365
- # ----------
366
- # method_name : str
367
- # The name of the method to check.
368
-
369
- # Returns
370
- # -------
371
- # bool
372
- # True if the method exists, False otherwise.
373
- # """
374
- # return hasattr(self.cls, method_name) if self.cls else False
375
-
376
- # def hasProperty(self, prop: str) -> bool:
377
- # """
378
- # Checks whether the specified property exists in the class.
379
-
380
- # Parameters
381
- # ----------
382
- # prop : str
383
- # The name of the property to check.
384
-
385
- # Returns
386
- # -------
387
- # bool
388
- # True if the property exists, False otherwise.
389
- # """
390
- # return hasattr(self.cls, prop) if self.cls else False
391
-
392
- # def hasConstant(self, constant: str) -> bool:
393
- # """
394
- # Checks whether the specified constant exists in the class.
395
-
396
- # Parameters
397
- # ----------
398
- # constant : str
399
- # The name of the constant to check.
400
-
401
- # Returns
402
- # -------
403
- # bool
404
- # True if the constant exists, False otherwise.
405
- # """
406
- # return hasattr(self.cls, constant) if self.cls else False
407
-
408
- # def getAttributes(self) -> List[str]:
409
- # """
410
- # Retrieves a list of all attributes (including methods and properties) of the class.
411
-
412
- # Returns
413
- # -------
414
- # list
415
- # A list of attribute names in the class.
416
- # """
417
- # return dir(self.cls) if self.cls else []
418
-
419
- # def getConstructor(self):
420
- # """
421
- # Retrieves the constructor (__init__) of the class.
422
-
423
- # Returns
424
- # -------
425
- # function or None
426
- # The constructor method if available, otherwise None.
427
- # """
428
- # return self.cls.__init__ if self.cls else None
429
-
430
- # def getDocComment(self) -> Optional[str]:
431
- # """
432
- # Retrieves the docstring of the class.
433
-
434
- # Returns
435
- # -------
436
- # str or None
437
- # The docstring of the class if available, otherwise None.
438
- # """
439
- # if not self.cls:
440
- # raise ValueError("Class not loaded. Use 'safeImport()' first.")
441
- # return self.cls.__doc__
442
-
443
- # def getFileName(self, remove_extension: bool = False) -> str:
444
- # """
445
- # Retrieves the file name where the class is defined, the same as `get_file()`.
446
-
447
- # Parameters
448
- # ----------
449
- # remove_extension : bool, optional
450
- # If True, the file extension will be removed from the filename. Default is False.
451
-
452
- # Returns
453
- # -------
454
- # str
455
- # The file name of the class definition.
456
- # """
457
- # file_name = os.path.basename(self.getFile())
458
- # if remove_extension:
459
- # file_name = os.path.splitext(file_name)[0]
460
- # return file_name
461
-
462
- # def getMethod(self, method_name: str):
463
- # """
464
- # Retrieves the specified method from the class.
465
-
466
- # Parameters
467
- # ----------
468
- # method_name : str
469
- # The name of the method to retrieve.
470
-
471
- # Returns
472
- # -------
473
- # function or None
474
- # The method if it exists, otherwise None.
475
- # """
476
- # return getattr(self.cls, method_name, None) if self.cls else None
477
-
478
- # def getMethods(self) -> List[str]:
479
- # """
480
- # Retrieves a list of all methods in the class.
481
-
482
- # Returns
483
- # -------
484
- # list
485
- # A list of method names in the class.
486
- # """
487
- # return [method for method, _ in inspect.getmembers(self.cls, predicate=inspect.isfunction)] if self.cls else []
488
-
489
- # def getName(self) -> str:
490
- # """
491
- # Retrieves the name of the class.
492
-
493
- # Returns
494
- # -------
495
- # str or None
496
- # The name of the class if available, otherwise None.
497
- # """
498
- # return self.cls.__name__ if self.cls else None
499
-
500
- # def getParentClass(self) -> Optional[tuple]:
501
- # """
502
- # Retrieves the parent classes (base classes) of the class.
503
-
504
- # Returns
505
- # -------
506
- # tuple or None
507
- # A tuple of base classes if available, otherwise None.
508
- # """
509
- # return self.cls.__bases__ if self.cls else None
510
-
511
- # def getProperties(self) -> List[str]:
512
- # """
513
- # Retrieves a list of all properties of the class.
514
-
515
- # Returns
516
- # -------
517
- # list
518
- # A list of property names in the class.
519
- # """
520
- # return [name for name, value in inspect.getmembers(self.cls, lambda x: isinstance(x, property))] if self.cls else []
521
-
522
- # def getProperty(self, prop: str):
523
- # """
524
- # Retrieves the specified property from the class.
525
-
526
- # Parameters
527
- # ----------
528
- # prop : str
529
- # The name of the property to retrieve.
530
-
531
- # Returns
532
- # -------
533
- # property or None
534
- # The property if it exists, otherwise None.
535
- # """
536
- # return getattr(self.cls, prop, None) if self.cls else None
537
-
538
- # def isAbstract(self) -> bool:
539
- # """
540
- # Checks whether the class is abstract.
541
-
542
- # Returns
543
- # -------
544
- # bool
545
- # True if the class is abstract, False otherwise.
546
- # """
547
- # return hasattr(self.cls, '__abstractmethods__') and bool(self.cls.__abstractmethods__) if self.cls else False
548
-
549
- # def isEnum(self) -> bool:
550
- # """
551
- # Checks whether the class is an enumeration.
552
-
553
- # Returns
554
- # -------
555
- # bool
556
- # True if the class is a subclass of Enum, False otherwise.
557
- # """
558
- # return self.cls is not None and isinstance(self.cls, type) and issubclass(self.cls, Enum)
559
-
560
- # def isSubclassOf(self, parent: type) -> bool:
561
- # """
562
- # Checks whether the class is a subclass of the specified parent class.
563
-
564
- # Parameters
565
- # ----------
566
- # parent : type
567
- # The parent class to check against.
568
-
569
- # Returns
570
- # -------
571
- # bool
572
- # True if the class is a subclass of the parent, False otherwise.
573
- # """
574
- # return self.cls is not None and issubclass(self.cls, parent)
575
-
576
- # def isInstanceOf(self, instance: Any) -> bool:
577
- # """
578
- # Checks whether the class is an instance of the specified class.
579
-
580
- # Parameters
581
- # ----------
582
- # parent : type
583
- # The class to check against.
584
-
585
- # Returns
586
- # -------
587
- # bool
588
- # True if the class is a subclass of the parent, False otherwise.
589
- # """
590
- # return self.cls is not None and isinstance(instance, self.cls)
591
-
592
- # def isIterable(self) -> bool:
593
- # """
594
- # Checks whether the class is iterable.
595
-
596
- # Returns
597
- # -------
598
- # bool
599
- # True if the class is iterable, False otherwise.
600
- # """
601
- # return hasattr(self.cls, '__iter__') if self.cls else False
602
-
603
- # def isInstantiable(self) -> bool:
604
- # """
605
- # Checks whether the class can be instantiated.
606
-
607
- # Returns
608
- # -------
609
- # bool
610
- # True if the class is callable and not abstract, False otherwise.
611
- # """
612
- # return self.cls is not None and callable(self.cls) and not self.isAbstract()
613
-
614
- # def newInstance(self, *args, **kwargs):
615
- # """
616
- # Creates a new instance of the class if it is instantiable.
617
-
618
- # Parameters
619
- # ----------
620
- # args : tuple
621
- # Arguments to pass to the class constructor.
622
- # kwargs : dict
623
- # Keyword arguments to pass to the class constructor.
624
-
625
- # Returns
626
- # -------
627
- # object
628
- # A new instance of the class.
629
-
630
- # Raises
631
- # ------
632
- # TypeError
633
- # If the class is not instantiable.
634
- # """
635
- # if self.isInstantiable():
636
- # return self.cls(*args, **kwargs)
637
- # raise TypeError(f"Cannot instantiate class '{self.classname}'. It may be abstract or not callable.")
638
-
639
- # def __str__(self) -> str:
640
- # """
641
- # Returns a string representation of the Reflection instance.
642
-
643
- # Returns
644
- # -------
645
- # str
646
- # A string describing the class and module.
647
- # """
648
- # status = "loaded" if self.cls else "not loaded"
649
- # return f"<Orionis Reflection class '{self.classname}' in module '{self.module_name}' ({status})>"
219
+ _ensure_valid_module(module)
220
+ _ensure_valid_class_name(module, class_name)
221
+ return ReflexionModuleWithClassName(module, class_name)