orionis 0.210.0__py3-none-any.whl → 0.211.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.211.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)
@@ -1,8 +1,7 @@
1
- from typing import Type, TypeVar
2
- import abc
1
+ from typing import Any, Callable, Dict, List, Optional, Tuple, Type, TypeVar
2
+ import inspect
3
3
 
4
4
  T = TypeVar('T')
5
- ABC = TypeVar('ABC', bound=abc.ABC)
6
5
 
7
6
  class ReflexionConcrete:
8
7
  """A reflection object encapsulating a concrete class.
@@ -22,3 +21,256 @@ class ReflexionConcrete:
22
21
  """Initialize with the concrete class."""
23
22
  self._concrete = concrete
24
23
 
24
+ def getClassName(self) -> str:
25
+ """Get the name of the concrete class.
26
+
27
+ Returns
28
+ -------
29
+ str
30
+ The name of the class
31
+ """
32
+ return self._concrete.__name__
33
+
34
+ def getClass(self) -> Type:
35
+ """Get the class of the instance.
36
+
37
+ Returns
38
+ -------
39
+ Type
40
+ The class object of the instance
41
+
42
+ Examples
43
+ --------
44
+ >>> reflex.getClass() is SomeClass
45
+ True
46
+ """
47
+ return self._concrete
48
+
49
+ def getModuleName(self) -> str:
50
+ """Get the name of the module where the class is defined.
51
+
52
+ Returns
53
+ -------
54
+ str
55
+ The module name
56
+ """
57
+ return self._concrete.__module__
58
+
59
+ def getAttributes(self) -> Dict[str, Any]:
60
+ """Get all class-level attributes.
61
+
62
+ Returns
63
+ -------
64
+ Dict[str, Any]
65
+ Dictionary of attribute names and their values
66
+ """
67
+ return {
68
+ k: v for k, v in vars(self._concrete).items()
69
+ if not callable(v) and not isinstance(v, staticmethod) and not isinstance(v, classmethod) and not k.startswith('_') and not isinstance(v, property)
70
+ }
71
+
72
+ def getMethods(self) -> List[str]:
73
+ """Get all method names of the class.
74
+
75
+ Returns
76
+ -------
77
+ List[str]
78
+ List of method names
79
+ """
80
+ return [
81
+ name for name, member in inspect.getmembers(self._concrete, predicate=inspect.isfunction)
82
+ if not name.startswith('_')
83
+ ]
84
+
85
+ def getStaticMethods(self) -> List[str]:
86
+ """Get all static method names of the class.
87
+
88
+ Returns
89
+ -------
90
+ List[str]
91
+ List of static method names, excluding private methods
92
+ """
93
+ return [
94
+ name for name in dir(self._concrete)
95
+ if not name.startswith('_') and isinstance(inspect.getattr_static(self._concrete, name), staticmethod)
96
+ ]
97
+
98
+ def getPropertyNames(self) -> List[str]:
99
+ """Get all property names of the class.
100
+
101
+ Returns
102
+ -------
103
+ List[str]
104
+ List of property names
105
+ """
106
+ return [
107
+ name for name, val in vars(self._concrete).items()
108
+ if isinstance(val, property)
109
+ ]
110
+
111
+ def getMethodSignature(self, methodName: str) -> inspect.Signature:
112
+ """Get the signature of a class method.
113
+
114
+ Parameters
115
+ ----------
116
+ methodName : str
117
+ Name of the method
118
+
119
+ Returns
120
+ -------
121
+ inspect.Signature
122
+ The method signature
123
+
124
+ Raises
125
+ ------
126
+ AttributeError
127
+ If the method doesn't exist
128
+ """
129
+ method = getattr(self._concrete, methodName)
130
+ if callable(method):
131
+ return inspect.signature(method)
132
+ raise AttributeError(f"{methodName} is not a valid method.")
133
+
134
+ def getPropertySignature(self, propertyName: str) -> inspect.Signature:
135
+ """Get the signature of a property getter.
136
+
137
+ Parameters
138
+ ----------
139
+ propertyName : str
140
+ Name of the property
141
+
142
+ Returns
143
+ -------
144
+ inspect.Signature
145
+ The property's getter method signature
146
+
147
+ Raises
148
+ ------
149
+ AttributeError
150
+ If the property doesn't exist or is not a property
151
+ """
152
+ attr = getattr(self._concrete, propertyName, None)
153
+ if isinstance(attr, property) and attr.fget is not None:
154
+ return inspect.signature(attr.fget)
155
+ raise AttributeError(f"{propertyName} is not a property or doesn't have a getter.")
156
+
157
+ def getDocstring(self) -> Optional[str]:
158
+ """Get the docstring of the class.
159
+
160
+ Returns
161
+ -------
162
+ Optional[str]
163
+ The class docstring, or None if not available
164
+ """
165
+ return self._concrete.__doc__
166
+
167
+ def getBaseClasses(self) -> Tuple[Type, ...]:
168
+ """Get the base classes of the class.
169
+
170
+ Returns
171
+ -------
172
+ Tuple[Type, ...]
173
+ Tuple of base classes
174
+ """
175
+ return self._concrete.__bases__
176
+
177
+ def isSubclassOf(self, cls: Type) -> bool:
178
+ """Check if the concrete class is a subclass of another.
179
+
180
+ Parameters
181
+ ----------
182
+ cls : Type
183
+ The parent class to check against
184
+
185
+ Returns
186
+ -------
187
+ bool
188
+ True if the concrete class is a subclass of the given class
189
+ """
190
+ return issubclass(self._concrete, cls)
191
+
192
+ def getSourceCode(self) -> Optional[str]:
193
+ """Get the source code of the class.
194
+
195
+ Returns
196
+ -------
197
+ Optional[str]
198
+ The source code if available, None otherwise
199
+ """
200
+ try:
201
+ return inspect.getsource(self._concrete)
202
+ except (TypeError, OSError):
203
+ return None
204
+
205
+ def getFileLocation(self) -> Optional[str]:
206
+ """Get the file location where the class is defined.
207
+
208
+ Returns
209
+ -------
210
+ Optional[str]
211
+ The file path if available, None otherwise
212
+ """
213
+ try:
214
+ return inspect.getfile(self._concrete)
215
+ except (TypeError, OSError):
216
+ return None
217
+
218
+ def getAnnotations(self) -> Dict[str, Any]:
219
+ """Get type annotations of the class.
220
+
221
+ Returns
222
+ -------
223
+ Dict[str, Any]
224
+ Dictionary of attribute names and their type annotations
225
+ """
226
+ return getattr(self._concrete, '__annotations__', {})
227
+
228
+ def hasAttribute(self, name: str) -> bool:
229
+ """Check if the class has a specific attribute.
230
+
231
+ Parameters
232
+ ----------
233
+ name : str
234
+ The attribute name to check
235
+
236
+ Returns
237
+ -------
238
+ bool
239
+ True if the attribute exists
240
+ """
241
+ return hasattr(self._concrete, name)
242
+
243
+ def getAttribute(self, name: str) -> Any:
244
+ """Get a class attribute by name.
245
+
246
+ Parameters
247
+ ----------
248
+ name : str
249
+ The attribute name
250
+
251
+ Returns
252
+ -------
253
+ Any
254
+ The attribute value
255
+
256
+ Raises
257
+ ------
258
+ AttributeError
259
+ If the attribute doesn't exist
260
+ """
261
+ return getattr(self._concrete, name)
262
+
263
+ def getCallableMembers(self) -> Dict[str, Callable]:
264
+ """Get all callable members (functions/methods) of the class.
265
+
266
+ Returns
267
+ -------
268
+ Dict[str, Callable]
269
+ Dictionary of method names and their callable objects
270
+ """
271
+ return {
272
+ name: member for name, member in inspect.getmembers(
273
+ self._concrete,
274
+ callable
275
+ ) if not name.startswith('__')
276
+ }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: orionis
3
- Version: 0.210.0
3
+ Version: 0.211.0
4
4
  Summary: Orionis Framework – Elegant, Fast, and Powerful.
5
5
  Home-page: https://github.com/orionis-framework/framework
6
6
  Author: Raul Mauricio Uñate Castro
@@ -1,6 +1,6 @@
1
1
  orionis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  orionis/console.py,sha256=4gYWxf0fWYgJ4RKwARvnTPh06FL3GJ6SAZ7R2NzOICw,1342
3
- orionis/framework.py,sha256=ktf77HKAC_3ZhF5oKg7CiAVmLkW_QmL_xrrzI7grIKU,1469
3
+ orionis/framework.py,sha256=fQ-g3NY9vLGmARML0s4UR0hYWEnxbuoim-HbOhJ-rYA,1469
4
4
  orionis/installer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  orionis/installer/manager.py,sha256=Li4TVziRXWfum02xNG4JHwbnLk-u8xzHjdqKz-D894k,2755
6
6
  orionis/installer/output.py,sha256=7O9qa2xtXMB_4ZvVi-Klneom9YazwygAd_4uYAoxhbU,8548
@@ -167,10 +167,10 @@ orionis/luminate/support/reflection.py,sha256=TbWZ_cer0PXrPlwCYFbUJRymlzYxXT0E4C
167
167
  orionis/luminate/support/std.py,sha256=TqrgMxF_i5ubYGT5LOvHCH7HOHNmI8CE1kG9pNoSniY,1390
168
168
  orionis/luminate/support/inspection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
169
169
  orionis/luminate/support/inspection/container_integrity.py,sha256=6d9FsGk-Rm1AXgqBS3Nww49dR7n1ptXTTNyGUuBHgNY,10111
170
- orionis/luminate/support/inspection/functions.py,sha256=XVDLdygONcfDNlH7CZ6muNdtYHLgNp5RybqC3smL4Y4,6400
171
- orionis/luminate/support/inspection/reflection.py,sha256=x_UHBY9pBSKgct13-u1WbhoONqLoGG60OpgoCsKE0AI,20368
170
+ orionis/luminate/support/inspection/functions.py,sha256=4wDT7iNp-5l4vuHk0UsIxN9wakASJRD4V0KY24uMDzk,7227
171
+ orionis/luminate/support/inspection/reflection.py,sha256=mOCamaKv1ED-Q60_01HMzsCAhoCFeDK7ZqYZ3iYepsM,7716
172
172
  orionis/luminate/support/inspection/reflexion_abstract.py,sha256=U_VAGQN0ZDMgjxYPhNrLxFt6F8_-8zXcA_B5djTV4GE,10731
173
- orionis/luminate/support/inspection/reflexion_concrete.py,sha256=0WOlLeTWLwMeAUReoaJetqlnT1_TxW_jMnbk_yXRR0g,549
173
+ orionis/luminate/support/inspection/reflexion_concrete.py,sha256=1ISuy2L6Oser-EhmpuGALmbauh7Z-X8Rx1YYgt5CabQ,7543
174
174
  orionis/luminate/support/inspection/reflexion_concrete_with_abstract.py,sha256=ZuAFoSPkgbOFMIbVR0hvlkKsm1dIpY1_bsXxZxvXcmU,801
175
175
  orionis/luminate/support/inspection/reflexion_instance.py,sha256=LNAgw4sZvHT7UMiObHTGk7xgqpIeKYHAQRgRpuPfEas,10842
176
176
  orionis/luminate/support/inspection/reflexion_instance_with_abstract.py,sha256=PI_VSH8baxjPgheOYc9tQAlLq9mjxGm5zCOr-bLVksg,9406
@@ -199,15 +199,17 @@ tests/example/test_example.py,sha256=8EYjl1b-J_479dmJdQoAcKCKr7JUydW7EmPQpeiF13Y
199
199
  tests/support/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
200
200
  tests/support/inspection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
201
201
  tests/support/inspection/test_reflection_abstract.py,sha256=K78avxUlI_dYKofSvVcuaVLAz-CivWSe3RkhrO-IRcA,9185
202
- tests/support/inspection/test_reflection_instance.py,sha256=qwYu_y3wiZzhegrRo97r1bWxW2YGxDdnnU-Hq4lZtAE,6930
203
- tests/support/inspection/test_reflection_instance_with_abstract.py,sha256=RNLf9RfRtM2nTY6Yfc8rPibSEVZkl8Pw2w962vsragk,4048
202
+ tests/support/inspection/test_reflection_concrete.py,sha256=dvO7dduJMCsioCxZ5i2WW6V5-3z5LR6gIgGvBGaQcNI,6542
203
+ tests/support/inspection/test_reflection_instance.py,sha256=iwwf-QY-O3kR_HTHdATUnu9iXn6Nat7d8Y8Hxhwfpb0,6938
204
+ tests/support/inspection/test_reflection_instance_with_abstract.py,sha256=RQkw2BYY8TLuk6h_9NIa_5JfRL7RG8004ro252t6YF8,4059
204
205
  tests/support/inspection/fakes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
205
206
  tests/support/inspection/fakes/fake_reflection_abstract.py,sha256=7qtz44brfFzE4oNYi9kIsvdWP79nP2FnzSz-0bU__pg,5045
207
+ tests/support/inspection/fakes/fake_reflection_concrete.py,sha256=j6gzsxE3xq5oJ30H_Hm1RsUwEY3jOYBu4sclxtD1ayo,1047
206
208
  tests/support/inspection/fakes/fake_reflection_instance.py,sha256=G16rZdJWC3L8SGEQkmwktvw4n7IAusIIx9Tm-ZFLcg4,1419
207
209
  tests/support/inspection/fakes/fake_reflection_instance_with_abstract.py,sha256=SfL8FuFmr650RlzXTrP4tGMfsPVZLhOxVnBXu_g1POg,1471
208
- orionis-0.210.0.dist-info/LICENCE,sha256=-_4cF2EBKuYVS_SQpy1uapq0oJPUU1vl_RUWSy2jJTo,1111
209
- orionis-0.210.0.dist-info/METADATA,sha256=lDNgDlBv95FLobuXCOJdgmXaXKt4SA5NkDmViO8yI1w,3003
210
- orionis-0.210.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
211
- orionis-0.210.0.dist-info/entry_points.txt,sha256=a_e0faeSqyUCVZd0MqljQ2oaHHdlsz6g9sU_bMqi5zQ,49
212
- orionis-0.210.0.dist-info/top_level.txt,sha256=2bdoHgyGZhOtLAXS6Om8OCTmL24dUMC_L1quMe_ETbk,14
213
- orionis-0.210.0.dist-info/RECORD,,
210
+ orionis-0.211.0.dist-info/LICENCE,sha256=-_4cF2EBKuYVS_SQpy1uapq0oJPUU1vl_RUWSy2jJTo,1111
211
+ orionis-0.211.0.dist-info/METADATA,sha256=Ib0VcpsiPdguGw9JroLhcBWsSoboYQRHUFUpVbUD1GU,3003
212
+ orionis-0.211.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
213
+ orionis-0.211.0.dist-info/entry_points.txt,sha256=a_e0faeSqyUCVZd0MqljQ2oaHHdlsz6g9sU_bMqi5zQ,49
214
+ orionis-0.211.0.dist-info/top_level.txt,sha256=2bdoHgyGZhOtLAXS6Om8OCTmL24dUMC_L1quMe_ETbk,14
215
+ orionis-0.211.0.dist-info/RECORD,,
@@ -0,0 +1,44 @@
1
+ class BaseExample:
2
+ """Base class to test inheritance."""
3
+
4
+ def baseMethod(self) -> str:
5
+ return "Base method called"
6
+
7
+ class FakeExample(BaseExample):
8
+ """This is a fake example class for testing reflection."""
9
+
10
+ class_attr: int = 42
11
+ another_attr = "hello"
12
+
13
+ def __init__(self, value: int = 10) -> None:
14
+ self.instance_attr = value
15
+
16
+ @property
17
+ def prop(self) -> int:
18
+ """A read-only property returning a fixed number."""
19
+ return 10
20
+
21
+ @property
22
+ def prop_with_getter(self) -> str:
23
+ return "read-only"
24
+
25
+ def method_one(self, x: int) -> int:
26
+ return x * 2
27
+
28
+ def method_two(self, a: str, b: str = "default") -> str:
29
+ return a + b
30
+
31
+ @staticmethod
32
+ def static_method() -> str:
33
+ return "I am static"
34
+
35
+ @staticmethod
36
+ def _private_static():
37
+ pass
38
+
39
+ @classmethod
40
+ def class_method(cls) -> str:
41
+ return f"I am class method of {cls.__name__}"
42
+
43
+ def _private_method(self):
44
+ pass
@@ -0,0 +1,139 @@
1
+ from orionis.luminate.support.inspection.reflection import Reflection
2
+ from orionis.luminate.support.inspection.reflexion_concrete import ReflexionConcrete
3
+ from orionis.luminate.test.test_case import TestCase
4
+ from tests.support.inspection.fakes.fake_reflection_concrete import BaseExample, FakeExample
5
+
6
+ class TestReflectionConcrete(TestCase):
7
+ """
8
+ Unit tests for the Reflection class.
9
+ """
10
+
11
+ def testReflectionConcreteExceptionValueError(self):
12
+ """Ensure Reflection.instance raises ValueError for invalid types."""
13
+ with self.assertRaises(ValueError):
14
+ Reflection.concrete(str)
15
+
16
+ def testReflectionConcrete(self):
17
+ """Verify Reflection.instance returns an instance of ReflexionInstance."""
18
+ self.assertIsInstance(Reflection.concrete(FakeExample), ReflexionConcrete)
19
+
20
+ def testReflectionConcreteGetClassName(self):
21
+ """Test getClassName method."""
22
+ reflection = Reflection.concrete(FakeExample)
23
+ self.assertEqual(reflection.getClassName(), "FakeExample")
24
+
25
+ def testReflectionConcreteGetClass(self):
26
+ """Test getClass method."""
27
+ reflection = Reflection.concrete(FakeExample)
28
+ self.assertEqual(reflection.getClass(), FakeExample)
29
+
30
+ def testReflectionConcreteGetModuleName(self):
31
+ """Test getModuleName method."""
32
+ reflection = Reflection.concrete(FakeExample)
33
+ self.assertEqual(reflection.getModuleName(), "tests.support.inspection.fakes.fake_reflection_concrete")
34
+
35
+ def testReflectionConcreteGetAttributes(self):
36
+ """Test getAttributes method."""
37
+ reflection = Reflection.concrete(FakeExample)
38
+ self.assertEqual(reflection.getAttributes(), {'class_attr': 42, 'another_attr': 'hello'})
39
+
40
+ def testReflectionConcreteGetMethods(self):
41
+ """Test getMethods method."""
42
+ reflection = Reflection.concrete(FakeExample)
43
+ expected_methods = [
44
+ 'baseMethod',
45
+ 'method_one',
46
+ 'method_two',
47
+ 'static_method',
48
+ ]
49
+ self.assertEqual(reflection.getMethods(), expected_methods)
50
+
51
+ def testReflectionConcreteGetStaticMethods(self):
52
+ """Test getStaticMethods method."""
53
+ reflection = Reflection.concrete(FakeExample)
54
+ expected_static_methods = [
55
+ 'static_method'
56
+ ]
57
+ self.assertEqual(reflection.getStaticMethods(), expected_static_methods)
58
+
59
+ def testReflectionConcreteGetPropertyNames(self):
60
+ """Test getPropertyNames method."""
61
+ reflection = Reflection.concrete(FakeExample)
62
+ expected_properties = [
63
+ 'prop',
64
+ 'prop_with_getter',
65
+ ]
66
+ self.assertEqual(reflection.getPropertyNames(), expected_properties)
67
+
68
+ def testReflectionConcreteGetMethodSignature(self):
69
+ """Test getMethodSignature method."""
70
+ reflection = Reflection.concrete(FakeExample)
71
+ self.assertEqual(str(reflection.getMethodSignature('method_one')), '(self, x: int) -> int')
72
+ self.assertEqual(str(reflection.getMethodSignature('method_two')), '(self, a: str, b: str = \'default\') -> str')
73
+ self.assertEqual(str(reflection.getMethodSignature('__init__')), '(self, value: int = 10) -> None')
74
+
75
+ def testReflectionConcreteGetPropertySignature(self):
76
+ """Test getPropertySignature method."""
77
+ reflection = Reflection.concrete(FakeExample)
78
+ self.assertEqual(str(reflection.getPropertySignature('prop')), '(self) -> int')
79
+ self.assertEqual(str(reflection.getPropertySignature('prop_with_getter')), '(self) -> str')
80
+
81
+ def testReflectionConcreteGetDocstring(self):
82
+ """Test getDocstring method."""
83
+ reflection = Reflection.concrete(FakeExample)
84
+ self.assertIn('This is a fake example class for testing reflection', reflection.getDocstring())
85
+
86
+ def testReflectionConcreteGetBaseClasses(self):
87
+ """Test getBaseClasses method."""
88
+ reflection = Reflection.concrete(FakeExample)
89
+ self.assertEqual(reflection.getBaseClasses(), (BaseExample,))
90
+
91
+ def testReflectionConcreteIsSubclassOf(self):
92
+ """Test isSubclassOf method."""
93
+ reflection = Reflection.concrete(FakeExample)
94
+ self.assertTrue(reflection.isSubclassOf(BaseExample))
95
+ self.assertFalse(reflection.isSubclassOf(str))
96
+
97
+ def testReflectionConcreteGetSourceCode(self):
98
+ """Test getSourceCode method."""
99
+ reflection = Reflection.concrete(FakeExample)
100
+ source_code = reflection.getSourceCode()
101
+ self.assertIn('class FakeExample(BaseExample):', source_code)
102
+ self.assertIn('def method_one(self, x: int) -> int:', source_code)
103
+
104
+ def testReflectionConcreteGetFileLocation(self):
105
+ """Test getFileLocation method."""
106
+ reflection = Reflection.concrete(FakeExample)
107
+ file_location = reflection.getFileLocation()
108
+ self.assertIn('fake_reflection_concrete.py', file_location)
109
+ self.assertIn('tests\\support\\inspection\\fakes', file_location)
110
+
111
+ def testReflectionConcreteGetAnnotations(self):
112
+ """Test getAnnotations method."""
113
+ reflection = Reflection.concrete(FakeExample)
114
+ self.assertEqual(reflection.getAnnotations(), {'class_attr': int})
115
+
116
+ def testReflectionConcreteHasAttribute(self):
117
+ """Test hasAttribute method."""
118
+ reflection = Reflection.concrete(FakeExample)
119
+ self.assertTrue(reflection.hasAttribute('class_attr'))
120
+ self.assertFalse(reflection.hasAttribute('non_existent_attr'))
121
+
122
+ def testReflectionConcreteGetAttribute(self):
123
+ """Test getAttribute method."""
124
+ reflection = Reflection.concrete(FakeExample)
125
+ self.assertEqual(reflection.getAttribute('class_attr'), 42)
126
+ with self.assertRaises(AttributeError):
127
+ reflection.getAttribute('non_existent_attr')
128
+
129
+ def testReflectionConcreteGetCallableMembers(self):
130
+ """Test getCallableMembers method."""
131
+ reflection = Reflection.concrete(FakeExample)
132
+ callable_members = reflection.getCallableMembers()
133
+ self.assertIn('_private_method', callable_members)
134
+ self.assertIn('_private_static', callable_members)
135
+ self.assertIn('baseMethod', callable_members)
136
+ self.assertIn('class_method', callable_members)
137
+ self.assertIn('method_one', callable_members)
138
+ self.assertIn('method_two', callable_members)
139
+ self.assertIn('static_method', callable_members)
@@ -3,7 +3,7 @@ from orionis.luminate.support.inspection.reflexion_instance import ReflexionInst
3
3
  from orionis.luminate.test.test_case import TestCase
4
4
  from tests.support.inspection.fakes.fake_reflection_instance import BaseFakeClass, FakeClass
5
5
 
6
- class TestReflection(TestCase):
6
+ class TestReflectionInstance(TestCase):
7
7
  """
8
8
  Unit tests for the Reflection class.
9
9
  """
@@ -2,7 +2,7 @@ from orionis.luminate.support.inspection.reflexion_instance_with_abstract import
2
2
  from orionis.luminate.test.test_case import TestCase
3
3
  from tests.support.inspection.fakes.fake_reflection_instance_with_abstract import FakeDataProcessor, IDataProcessor
4
4
 
5
- class TestReflexionWithFakes(TestCase):
5
+ class TestReflexionInstanceWithAbstract(TestCase):
6
6
 
7
7
  def testReflexionInstanceWithAbstractGetImplementationAnalysis(self):
8
8
  """Test reflexion con IDataProcessor y FakeDataProcessor."""