orionis 0.603.0__py3-none-any.whl → 0.605.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.
@@ -5,7 +5,7 @@
5
5
  NAME = "orionis"
6
6
 
7
7
  # Current version of the framework
8
- VERSION = "0.603.0"
8
+ VERSION = "0.605.0"
9
9
 
10
10
  # Full name of the author or maintainer of the project
11
11
  AUTHOR = "Raul Mauricio Uñate Castro"
@@ -0,0 +1,233 @@
1
+ from dataclasses import MISSING, asdict, fields, is_dataclass
2
+ from enum import Enum
3
+
4
+ from orionis.support.standard.std import StdClass
5
+
6
+ class DataClass:
7
+
8
+ def __init__(self, dataclass_cls: type):
9
+ """
10
+ Initialize the DataClass wrapper with a dataclass type.
11
+
12
+ Parameters
13
+ ----------
14
+ dataclass_cls : type
15
+ The class to be wrapped. Must be a dataclass type.
16
+
17
+ Returns
18
+ -------
19
+ None
20
+
21
+ Raises
22
+ ------
23
+ ValueError
24
+ If the provided class is not a dataclass type or is an instance.
25
+
26
+ Notes
27
+ -----
28
+ This constructor validates that the input is a dataclass type (not an instance).
29
+ If valid, it stores the class for further operations and initializes internal
30
+ dictionaries for property management. Raises an error if the input is not a valid
31
+ dataclass type.
32
+ """
33
+
34
+ # Ensure the provided class is a dataclass and not an instance
35
+ if not (is_dataclass(dataclass_cls) and isinstance(dataclass_cls, type)):
36
+ raise ValueError(
37
+ f"The provided class '{getattr(dataclass_cls, '__name__', type(dataclass_cls).__name__)}' must be a dataclass type, not an instance."
38
+ )
39
+
40
+ # Store the dataclass type for use in other methods
41
+ self.__cls = dataclass_cls
42
+
43
+ # Initialize dictionaries to manage strict and extra properties
44
+ self.__strict_properties = {}
45
+ self.__extra_properties = {}
46
+
47
+ def getOriginalProperties(self) -> set:
48
+ """
49
+ Get the set of original field names defined in the wrapped dataclass type.
50
+
51
+ Parameters
52
+ ----------
53
+ None
54
+
55
+ Returns
56
+ -------
57
+ set of str
58
+ Set containing the names of all original fields defined in the dataclass type.
59
+
60
+ Raises
61
+ ------
62
+ AttributeError
63
+ If the wrapped class does not have dataclass fields.
64
+
65
+ Notes
66
+ -----
67
+ This method retrieves the field names from the dataclass type stored in `self.__cls`.
68
+ If the internal reference is an instance, its type is used to access the field definitions.
69
+ The returned set includes only the names of fields originally declared in the dataclass,
70
+ excluding any dynamically added attributes.
71
+ """
72
+
73
+ # Use the class stored in self.__cls; if it's an instance, get its type
74
+ cls = self.__cls
75
+ if not isinstance(cls, type):
76
+ cls = type(cls)
77
+
78
+ # Return the set of field names defined in the dataclass
79
+ return set(cls.__dataclass_fields__.keys())
80
+
81
+ def fromDict(self, props: dict) -> 'DataClass':
82
+ """
83
+ Populate the wrapped dataclass instance with properties from a dictionary.
84
+
85
+ Parameters
86
+ ----------
87
+ props : dict
88
+ Dictionary containing property names and values to assign to the dataclass instance.
89
+
90
+ Returns
91
+ -------
92
+ DataClass
93
+ The current instance of the DataClass wrapper, with the dataclass instance populated
94
+ according to the provided dictionary. The internal reference (`self.__cls`) is updated
95
+ to the new dataclass instance created with the provided properties.
96
+
97
+ Raises
98
+ ------
99
+ ValueError
100
+ If the `props` parameter is not a dictionary.
101
+
102
+ Notes
103
+ -----
104
+ - Properties matching the original dataclass fields are assigned as strict properties.
105
+ - Properties not matching the original fields are assigned as extra properties and set as attributes.
106
+ - The method creates a new instance of the dataclass using only the strict properties, then sets extra properties as attributes.
107
+ - The dataclass type itself is not modified; only the instance managed by this wrapper is updated.
108
+ """
109
+
110
+ # Ensure the input is a dictionary
111
+ if not isinstance(props, dict):
112
+ raise ValueError("The 'props' parameter must be a dictionary.")
113
+
114
+ # Get the set of original field names from the dataclass
115
+ original_fields = self.getOriginalProperties()
116
+
117
+ # Separate strict (original) and extra properties
118
+ for key, value in props.items():
119
+ if key in original_fields:
120
+ self.__strict_properties[key] = value # Assign to strict properties
121
+ else:
122
+ self.__extra_properties[key] = value # Assign to extra properties
123
+
124
+ # Create a new instance of the dataclass with strict properties only
125
+ instance = self.__cls(**self.__strict_properties)
126
+
127
+ # Set extra properties as attributes on the instance
128
+ for key, value in self.__extra_properties.items():
129
+ instance.__setattr__(key, value)
130
+
131
+ # Update the internal reference to the new instance
132
+ self.__cls = instance
133
+
134
+ # Return self to allow method chaining
135
+ return self
136
+
137
+ def fromDataclass(self, instance) -> 'DataClass':
138
+ """
139
+ Populate the wrapped dataclass instance with properties from another dataclass instance.
140
+
141
+ Parameters
142
+ ----------
143
+ instance : object
144
+ An instance of a dataclass from which properties will be extracted and assigned to the wrapped dataclass.
145
+
146
+ Returns
147
+ -------
148
+ DataClass
149
+ Returns the current instance of the DataClass wrapper after populating its internal dataclass instance
150
+ with the properties extracted from the provided dataclass instance.
151
+
152
+ Raises
153
+ ------
154
+ ValueError
155
+ If the provided `instance` is not a dataclass.
156
+
157
+ Notes
158
+ -----
159
+ This method extracts all properties from the provided dataclass instance using `asdict` if it is already
160
+ initialized (i.e., not a class). If the input is a dataclass type, it extracts properties from its `__dict__`.
161
+ The extracted properties are then delegated to `fromDict`, which handles property validation and assignment,
162
+ including strict property checking if enabled.
163
+ """
164
+
165
+ # Ensure the provided instance is a dataclass
166
+ if not is_dataclass(instance):
167
+ raise ValueError("The provided instance is not a dataclass.")
168
+
169
+ # Extract properties from the dataclass instance using asdict if it's an instance,
170
+ # otherwise use __dict__ for class-level attributes
171
+ if is_dataclass(instance) and not isinstance(instance, type):
172
+ props = asdict(instance)
173
+ else:
174
+ props = {k: v for k, v in instance.__dict__.items() if not k.startswith("__")}
175
+
176
+ # Delegate property assignment to fromDict, which handles validation and assignment
177
+ return self.fromDict(props)
178
+
179
+ def get(self) -> type:
180
+ """
181
+ Retrieve the dataclass type or instance currently managed by this wrapper.
182
+
183
+ Returns
184
+ -------
185
+ type or object
186
+ Returns the dataclass type if no instance has been set, or the dataclass instance if one has been created and assigned.
187
+ The returned value reflects the current state of the wrapper: either the original dataclass type or the most recently set instance.
188
+
189
+ Notes
190
+ -----
191
+ This method provides direct access to the underlying dataclass type or instance managed by the wrapper.
192
+ It is useful for introspection, further manipulation, or integration with other components.
193
+ The returned value is determined by the internal state of the wrapper (`self.__cls`), which may be either a class or an instance.
194
+ """
195
+
196
+ # Return the current dataclass type or instance managed by the wrapper
197
+ return self.__cls
198
+
199
+ def toDict(self) -> dict:
200
+ """
201
+ Convert the managed dataclass instance to a dictionary representation, including both original fields and any extra properties.
202
+
203
+ Parameters
204
+ ----------
205
+ None
206
+
207
+ Returns
208
+ -------
209
+ dict
210
+ Dictionary containing all original dataclass fields and any extra properties added to the instance.
211
+ - If the internal reference is an instance, original fields are recursively converted using `dataclasses.asdict`.
212
+ - Extra properties (not defined in the dataclass) are merged into the result.
213
+ - If the internal reference is still a class (not an instance), only strict properties are returned.
214
+
215
+ Notes
216
+ -----
217
+ - Original dataclass fields are obtained using `dataclasses.asdict` for instances.
218
+ - Extra properties are those added to the instance that are not part of the original dataclass definition.
219
+ - The returned dictionary represents the complete state of the managed dataclass instance, including dynamic attributes.
220
+ """
221
+
222
+ # If self.__cls is an instance, use asdict to get original (strict) properties
223
+ if not isinstance(self.__cls, type):
224
+ result = asdict(self.__cls)
225
+ else:
226
+ # If it's still a class, just return the strict properties dictionary
227
+ result = dict(self.__strict_properties)
228
+
229
+ # Merge extra properties (not defined in the dataclass) into the result
230
+ result.update(self.__extra_properties)
231
+
232
+ # Return the combined dictionary
233
+ return result
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: orionis
3
- Version: 0.603.0
3
+ Version: 0.605.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
@@ -103,7 +103,7 @@ orionis/failure/contracts/handler.py,sha256=AeJfkJfD3hTkOIYAtADq6GnQfq-qWgDfUc7b
103
103
  orionis/failure/entities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
104
104
  orionis/failure/entities/throwable.py,sha256=1zD-awcuAyEtlR-L7V7ZIfPSF4GpXkf-neL5sXul7dc,1240
105
105
  orionis/foundation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
106
- orionis/foundation/application.py,sha256=_pws-r2QSTTvIonmt9bEBUwOpDvPQkAMNi3IsUpNY8E,82664
106
+ orionis/foundation/application.py,sha256=kSSR6uxaElgkh2fzR3EPBM1XCbnJLLE8l4FpttzsEPk,88193
107
107
  orionis/foundation/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
108
108
  orionis/foundation/config/startup.py,sha256=btqvryeIf9lLNQ9fBff7bJMrfraEY8qrWi4y_5YAR0Q,9681
109
109
  orionis/foundation/config/app/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -217,7 +217,7 @@ orionis/foundation/providers/scheduler_provider.py,sha256=irwkjMiq-HpsbJxAOnhjji
217
217
  orionis/foundation/providers/testing_provider.py,sha256=2akFnabtH_cV_7z_2cCL7u8cPCGvCJAmlhMcnlCrc4c,3742
218
218
  orionis/foundation/providers/workers_provider.py,sha256=P_YtJuPNrdJAQJkAqI11KI0c6GSB9NqIuuCKpRytE0g,3937
219
219
  orionis/metadata/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
220
- orionis/metadata/framework.py,sha256=hxzdtDuk8fEhzryzkVy_FirXfQNZt0n9Qzqb-960y0E,4109
220
+ orionis/metadata/framework.py,sha256=110OVacTpVP1vOd_IzObZbki4RXx9TVLY4wF9srLw_M,4109
221
221
  orionis/metadata/package.py,sha256=k7Yriyp5aUcR-iR8SK2ec_lf0_Cyc-C7JczgXa-I67w,16039
222
222
  orionis/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
223
223
  orionis/services/asynchrony/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -270,8 +270,6 @@ orionis/services/introspection/concretes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5
270
270
  orionis/services/introspection/concretes/reflection.py,sha256=ZOScKOATUNA-gOJIG_8Z2Q5XXI2kAmDRCg8fg2SFklg,55872
271
271
  orionis/services/introspection/concretes/contracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
272
272
  orionis/services/introspection/concretes/contracts/reflection.py,sha256=LwEAgdN_WLCfS9b8pnFRVfN0PTRK4Br9qngu5km5aIk,24955
273
- orionis/services/introspection/dataclass/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
274
- orionis/services/introspection/dataclass/extractor.py,sha256=8nDoZYnyWTA4o8DTCM6rFNpOKnQR5O0aZk5oC5domXs,1700
275
273
  orionis/services/introspection/dependencies/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
276
274
  orionis/services/introspection/dependencies/reflection.py,sha256=3aQl541JkohRcoZFxQGiGPz3CnBMK8gmcRwO9XiLSY0,13906
277
275
  orionis/services/introspection/dependencies/contracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -357,6 +355,7 @@ orionis/support/standard/contracts/std.py,sha256=SJ44qIFDCp4jHL18k4sji5Mt_MN16lp
357
355
  orionis/support/standard/exceptions/__init__.py,sha256=GovJ24C8fCOlnU5_TrMJKngYNcJ1rvJnF9WFTA8ktyw,96
358
356
  orionis/support/standard/exceptions/standard.py,sha256=BM0VHLRYD7SzoMJkaA7BxY5280v81hlj1Xslu0UaFag,788
359
357
  orionis/support/wrapper/__init__.py,sha256=jGoWoIGYuRYqMYQKlrX7Dpcbg-AGkHoB_aM2xhu73yc,62
358
+ orionis/support/wrapper/dataclass.py,sha256=uNihcPLxUYQZ_ZFWM_SaJ8xqpZ66KceE18xNBwL7r18,9525
360
359
  orionis/support/wrapper/dot_dict.py,sha256=T8xWwwOhBZHNeXRwE_CxvOwG9UFxsLqNmOJjV2CNIrc,7284
361
360
  orionis/test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
362
361
  orionis/test/kernel.py,sha256=gZARnbvdz193WE-gdOiZvtUsuwHCGHHAw07conCNWMo,4019
@@ -405,8 +404,8 @@ orionis/test/validators/workers.py,sha256=rWcdRexINNEmGaO7mnc1MKUxkHKxrTsVuHgbnI
405
404
  orionis/test/view/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
406
405
  orionis/test/view/render.py,sha256=R55ykeRs0wDKcdTf4O1YZ8GDHTFmJ0IK6VQkbJkYUvo,5571
407
406
  orionis/test/view/report.stub,sha256=QLqqCdRoENr3ECiritRB3DO_MOjRQvgBh5jxZ3Hs1r0,28189
408
- orionis-0.603.0.dist-info/licenses/LICENCE,sha256=JhC-z_9mbpUrCfPjcl3DhDA8trNDMzb57cvRSam1avc,1463
409
- orionis-0.603.0.dist-info/METADATA,sha256=8hi5AZgoNofNT1vP7LzZGA6R6Rbue7G9q7Ws0ghhunk,4801
410
- orionis-0.603.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
411
- orionis-0.603.0.dist-info/top_level.txt,sha256=lyXi6jArpqJ-0zzNqd_uwsH-z9TCEBVBL-pC3Ekv7hU,8
412
- orionis-0.603.0.dist-info/RECORD,,
407
+ orionis-0.605.0.dist-info/licenses/LICENCE,sha256=JhC-z_9mbpUrCfPjcl3DhDA8trNDMzb57cvRSam1avc,1463
408
+ orionis-0.605.0.dist-info/METADATA,sha256=6c_7Q48WCF7aakbfOg4zyfjC-ORNJf7VqD2mIyutUZo,4801
409
+ orionis-0.605.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
410
+ orionis-0.605.0.dist-info/top_level.txt,sha256=lyXi6jArpqJ-0zzNqd_uwsH-z9TCEBVBL-pC3Ekv7hU,8
411
+ orionis-0.605.0.dist-info/RECORD,,
File without changes
@@ -1,45 +0,0 @@
1
- class DataclassInspector:
2
-
3
- def __call__(self, dataclass_type: type) -> dict:
4
- """
5
- Extract attributes and their values from a given dataclass type.
6
-
7
- This method retrieves all attributes defined in the provided dataclass type,
8
- excluding special attributes (those whose names start with '__'). It returns
9
- a dictionary where the keys are the attribute names and the values are the
10
- corresponding attribute values.
11
-
12
- Parameters
13
- ----------
14
- dataclass_type : type
15
- The dataclass type from which to extract attributes. This must be a valid
16
- Python class type.
17
-
18
- Returns
19
- -------
20
- dict
21
- A dictionary where:
22
- - Keys are the names of the attributes defined in the dataclass type.
23
- - Values are the corresponding attribute values.
24
- Special attributes (those starting with '__') are excluded.
25
-
26
- Raises
27
- ------
28
- TypeError
29
- If the provided argument is not a valid Python class type.
30
- """
31
-
32
- # Ensure the input is a valid class type
33
- if isinstance(dataclass_type, type):
34
-
35
- # Extract attributes and their values, excluding special attributes
36
- values = {k: v for k, v in dataclass_type.__dict__.items() if not k.startswith("__")}
37
-
38
- # Return the extracted attributes and their values
39
- return values
40
-
41
- # Raise an error if the input is not a valid class type
42
- raise TypeError("The provided argument is not a valid dataclass type.")
43
-
44
- # Instantiate the DataclassValues callable
45
- extractor = DataclassInspector()