orionis 0.435.0__py3-none-any.whl → 0.437.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.
Files changed (59) hide show
  1. orionis/console/contracts/kernel.py +16 -3
  2. orionis/console/dumper/contracts/dump.py +8 -9
  3. orionis/console/dynamic/progress_bar.py +21 -29
  4. orionis/console/output/console.py +12 -0
  5. orionis/container/context/manager.py +27 -17
  6. orionis/container/context/scope.py +8 -7
  7. orionis/container/contracts/service_provider.py +12 -8
  8. orionis/container/providers/service_provider.py +9 -16
  9. orionis/container/resolver/resolver.py +29 -22
  10. orionis/foundation/contracts/application.py +437 -47
  11. orionis/foundation/contracts/config.py +14 -6
  12. orionis/foundation/providers/console_provider.py +16 -15
  13. orionis/foundation/providers/dumper_provider.py +20 -8
  14. orionis/foundation/providers/logger_provider.py +19 -14
  15. orionis/foundation/providers/path_resolver_provider.py +17 -14
  16. orionis/foundation/providers/progress_bar_provider.py +15 -14
  17. orionis/foundation/providers/testing_provider.py +20 -14
  18. orionis/foundation/providers/workers_provider.py +19 -14
  19. orionis/metadata/framework.py +1 -1
  20. orionis/services/asynchrony/contracts/coroutines.py +5 -9
  21. orionis/services/asynchrony/coroutines.py +10 -23
  22. orionis/services/asynchrony/exceptions/exception.py +3 -3
  23. orionis/services/environment/contracts/caster.py +8 -9
  24. orionis/services/environment/contracts/env.py +9 -9
  25. orionis/services/environment/core/dot_env.py +56 -71
  26. orionis/services/environment/dynamic/caster.py +215 -215
  27. orionis/services/environment/enums/__init__.py +5 -0
  28. orionis/services/environment/enums/value_type.py +22 -25
  29. orionis/services/environment/env.py +28 -12
  30. orionis/services/environment/exceptions/exception.py +6 -2
  31. orionis/services/environment/exceptions/value.py +6 -2
  32. orionis/services/environment/helpers/functions.py +5 -3
  33. orionis/services/environment/key/key_generator.py +8 -11
  34. orionis/services/environment/validators/__init__.py +7 -0
  35. orionis/services/environment/validators/key_name.py +5 -5
  36. orionis/services/environment/validators/types.py +29 -9
  37. orionis/services/introspection/abstract/contracts/reflection.py +188 -221
  38. orionis/services/introspection/abstract/reflection.py +311 -178
  39. orionis/services/introspection/callables/contracts/reflection.py +64 -21
  40. orionis/services/introspection/callables/reflection.py +98 -23
  41. orionis/services/introspection/concretes/reflection.py +278 -181
  42. orionis/services/introspection/dependencies/contracts/reflection.py +21 -18
  43. orionis/services/introspection/dependencies/entities/callable_dependencies.py +15 -16
  44. orionis/services/introspection/dependencies/entities/class_dependencies.py +24 -16
  45. orionis/services/introspection/dependencies/entities/known_dependencies.py +19 -13
  46. orionis/services/introspection/dependencies/entities/method_dependencies.py +22 -16
  47. orionis/services/introspection/dependencies/reflection.py +0 -3
  48. orionis/services/introspection/instances/reflection.py +16 -6
  49. orionis/services/log/contracts/log_service.py +4 -0
  50. orionis/services/log/handlers/filename.py +2 -0
  51. orionis/services/paths/contracts/resolver.py +0 -3
  52. orionis/services/paths/resolver.py +0 -3
  53. {orionis-0.435.0.dist-info → orionis-0.437.0.dist-info}/METADATA +1 -1
  54. {orionis-0.435.0.dist-info → orionis-0.437.0.dist-info}/RECORD +59 -59
  55. /orionis/services/introspection/concretes/contracts/{concrete.py → reflection.py} +0 -0
  56. {orionis-0.435.0.dist-info → orionis-0.437.0.dist-info}/WHEEL +0 -0
  57. {orionis-0.435.0.dist-info → orionis-0.437.0.dist-info}/licenses/LICENCE +0 -0
  58. {orionis-0.435.0.dist-info → orionis-0.437.0.dist-info}/top_level.txt +0 -0
  59. {orionis-0.435.0.dist-info → orionis-0.437.0.dist-info}/zip-safe +0 -0
@@ -1,4 +1,3 @@
1
-
2
1
  from typing import Any
3
2
  from orionis.services.environment.contracts.caster import IEnvironmentCaster
4
3
  from orionis.services.environment.enums.value_type import EnvironmentValueType
@@ -12,12 +11,12 @@ class EnvironmentCaster(IEnvironmentCaster):
12
11
  @staticmethod
13
12
  def options() -> set:
14
13
  """
15
- Returns the set of valid type hints that can be used with this Type class.
14
+ Get the set of valid type hints supported by this class.
16
15
 
17
16
  Returns
18
17
  -------
19
18
  set
20
- A set containing the valid type hints.
19
+ Set of valid type hint strings that can be used for environment value casting.
21
20
  """
22
21
  return EnvironmentCaster.OPTIONS
23
22
 
@@ -26,15 +25,16 @@ class EnvironmentCaster(IEnvironmentCaster):
26
25
  raw: str | Any
27
26
  ) -> None:
28
27
  """
29
- Initializes an EnvTypes instance by parsing a raw input into a type hint and value.
28
+ Parse the input `raw` to extract a type hint and value for environment variable casting.
30
29
 
31
30
  Parameters
32
31
  ----------
33
32
  raw : str or Any
34
- The input to be parsed. If a string, it may contain a type hint and value separated by a colon
35
- (e.g., "int: 42"). If a colon is present, the part before the colon is treated as the type hint
36
- and the part after as the value. If no colon is present, the entire string is treated as the value
37
- with no type hint. If not a string, the input is treated as the value with no type hint.
33
+ The input value to be parsed. If a string, it may contain a type hint and value
34
+ separated by a colon (e.g., "int: 42"). If a colon is present, the part before
35
+ the colon is treated as the type hint and the part after as the value. If no colon
36
+ is present, the entire string is treated as the value with no type hint. If not a
37
+ string, the input is treated as the value with no type hint.
38
38
 
39
39
  Attributes
40
40
  ----------
@@ -43,22 +43,25 @@ class EnvironmentCaster(IEnvironmentCaster):
43
43
  __value_raw : str or Any
44
44
  The extracted value string if input is a string, or the raw value otherwise.
45
45
 
46
- Returns
47
- -------
48
- None
49
- This constructor does not return a value. It initializes the instance attributes.
46
+ Notes
47
+ -----
48
+ This constructor does not return a value. It initializes the instance attributes
49
+ for type hint and raw value, which are used for subsequent type casting operations.
50
50
  """
51
+
51
52
  # Initialize type hint and value to default None
52
53
  self.__type_hint: str = None
53
54
  self.__value_raw: str | Any = None
54
55
 
55
56
  # If the input is a string, attempt to parse type hint and value
56
57
  if isinstance(raw, str):
58
+
57
59
  # Remove leading whitespace from the input
58
60
  self.__value_raw = raw.lstrip()
59
61
 
60
62
  # Check if the string contains a colon, indicating a type hint
61
63
  if ':' in self.__value_raw:
64
+
62
65
  # Split at the first colon to separate type hint and value
63
66
  type_hint, value_str = raw.split(':', 1)
64
67
 
@@ -68,30 +71,32 @@ class EnvironmentCaster(IEnvironmentCaster):
68
71
  # Remove leading whitespace from the value part
69
72
  self.__value_raw = value_str.lstrip() if value_str else None
70
73
  else:
74
+
71
75
  # If input is not a string, treat it as the value with no type hint
72
76
  self.__value_raw = raw
73
77
 
74
78
  def get(self):
75
79
  """
76
- Retrieves the value processed according to the specified type hint.
80
+ Returns the processed value based on the specified type hint.
77
81
 
78
- This method checks if a valid type hint is present and dispatches the call to the
79
- corresponding internal parsing method for that type. Supported type hints include:
80
- 'path', 'str', 'int', 'float', 'bool', 'list', 'dict', 'tuple', and 'set'.
82
+ If a valid type hint is present, this method dispatches to the corresponding
83
+ internal parsing method for that type. Supported type hints include: 'path',
84
+ 'str', 'int', 'float', 'bool', 'list', 'dict', 'tuple', 'set', and 'base64'.
81
85
  If no type hint is set, the raw value is returned as is.
82
86
 
83
87
  Returns
84
88
  -------
85
89
  Any
86
- The value converted or processed according to the specified type hint. If no type hint
87
- is set, returns the raw value.
90
+ The value converted or processed according to the specified type hint.
91
+ If no type hint is set, returns the raw value.
88
92
 
89
93
  Raises
90
94
  ------
91
95
  OrionisEnvironmentValueError
92
- If the type hint is not one of the supported options.
96
+ If an error occurs during type conversion or processing.
93
97
  """
94
98
 
99
+ # Attempt to process the value based on the type hint
95
100
  try:
96
101
 
97
102
  # If a type hint is set, dispatch to the appropriate parsing method
@@ -138,6 +143,7 @@ class EnvironmentCaster(IEnvironmentCaster):
138
143
  return self.__parseBase64()
139
144
 
140
145
  else:
146
+
141
147
  # If no type hint is set, return the raw value
142
148
  return self.__value_raw
143
149
 
@@ -155,30 +161,31 @@ class EnvironmentCaster(IEnvironmentCaster):
155
161
 
156
162
  def to(self, type_hint: str | EnvironmentValueType) -> Any:
157
163
  """
158
- Converts the internal value to the specified type and returns its string representation with the type hint prefix.
159
-
160
- This method sets the type hint for the instance and attempts to convert the internal value to the specified type.
161
- The type hint must be one of the valid options defined in `OPTIONS`. If the conversion is successful, a string
162
- representation of the value prefixed with the type hint is returned. If the type hint is invalid or the conversion
163
- fails, an exception is raised.
164
+ Convert the internal value to the specified type and return its string representation
165
+ with the type hint prefix.
164
166
 
165
167
  Parameters
166
168
  ----------
167
169
  type_hint : str or EnvironmentValueType
168
- The type hint to set. Can be a string or an `EnvironmentValueType` enum member. Must be one of the valid options.
170
+ The type to which the internal value should be converted. Can be a string or an
171
+ EnvironmentValueType enum member. Must be one of the valid options in `OPTIONS`.
169
172
 
170
173
  Returns
171
174
  -------
172
175
  Any
173
- The string representation of the value with the type hint prefix, according to the specified type.
174
- For example, "int:42", "list:[1, 2, 3]", etc.
176
+ The string representation of the value with the type hint prefix, according to the
177
+ specified type. For example, "int:42", "list:[1, 2, 3]", etc.
175
178
 
176
179
  Raises
177
180
  ------
178
181
  OrionisEnvironmentValueError
179
- If the provided type hint is not valid or if the value cannot be converted to the specified type.
182
+ If the provided type hint is not valid or if the value cannot be converted to the
183
+ specified type.
180
184
  """
185
+
186
+ # Validate the type hint and ensure it is one of the defined options
181
187
  try:
188
+
182
189
  # If type_hint is an enum, convert it to its value string
183
190
  if isinstance(type_hint, EnvironmentValueType):
184
191
  type_hint = type_hint.value
@@ -195,30 +202,50 @@ class EnvironmentCaster(IEnvironmentCaster):
195
202
  # Dispatch to the appropriate conversion method based on the type hint
196
203
  if self.__type_hint == EnvironmentValueType.PATH.value:
197
204
  return self.__toPath()
205
+
206
+ # If the type hint is 'str', convert to string
198
207
  if self.__type_hint == EnvironmentValueType.STR.value:
199
208
  return self.__toStr()
209
+
210
+ # If the type hint is 'int', convert to integer
200
211
  if self.__type_hint == EnvironmentValueType.INT.value:
201
212
  return self.__toInt()
213
+
214
+ # If the type hint is 'float', convert to float
202
215
  if self.__type_hint == EnvironmentValueType.FLOAT.value:
203
216
  return self.__toFloat()
217
+
218
+ # If the type hint is 'bool', convert to boolean
204
219
  if self.__type_hint == EnvironmentValueType.BOOL.value:
205
220
  return self.__toBool()
221
+
222
+ # If the type hint is 'list', convert to list
206
223
  if self.__type_hint == EnvironmentValueType.LIST.value:
207
224
  return self.__toList()
225
+
226
+ # If the type hint is 'dict', convert to dictionary
208
227
  if self.__type_hint == EnvironmentValueType.DICT.value:
209
228
  return self.__toDict()
229
+
230
+ # If the type hint is 'tuple', convert to tuple
210
231
  if self.__type_hint == EnvironmentValueType.TUPLE.value:
211
232
  return self.__toTuple()
233
+
234
+ # If the type hint is 'set', convert to set
212
235
  if self.__type_hint == EnvironmentValueType.SET.value:
213
236
  return self.__toSet()
237
+
238
+ # If the type hint is 'base64', convert to Base64 encoded string
214
239
  if self.__type_hint == EnvironmentValueType.BASE64.value:
215
240
  return self.__toBase64()
216
241
 
217
242
  except OrionisEnvironmentValueError:
243
+
218
244
  # Propagate specific type conversion errors
219
245
  raise
220
246
 
221
247
  except Exception as e:
248
+
222
249
  # Catch any other unexpected errors and wrap them in an environment value error
223
250
  raise OrionisEnvironmentValueError(
224
251
  f"Error converting value '{self.__value_raw}' to type '{type_hint}': {str(e)}"
@@ -226,24 +253,24 @@ class EnvironmentCaster(IEnvironmentCaster):
226
253
 
227
254
  def __toBase64(self) -> str:
228
255
  """
229
- Converts the internal value to a Base64 encoded string with the type hint prefix.
230
-
231
- This method checks if the internal value is a string or bytes. If so, it encodes the value in Base64
232
- and returns a string in the format "<type_hint>:<base64_value>". If the internal value is not a string
233
- or bytes, an exception is raised.
256
+ Convert the internal value to a Base64 encoded string with the type hint prefix.
234
257
 
235
258
  Returns
236
259
  -------
237
260
  str
238
- A Base64 encoded string combining the type hint and the internal value, separated by a colon.
261
+ A string in the format "<type_hint>:<base64_value>", where <base64_value> is the Base64
262
+ encoded representation of the internal value.
239
263
 
240
264
  Raises
241
265
  ------
242
266
  OrionisEnvironmentValueError
243
267
  If the internal value is not a string or bytes.
244
268
  """
269
+
270
+ # Import the base64 module for encoding
245
271
  import base64
246
272
 
273
+ # Ensure the internal value is a string or bytes before encoding
247
274
  if not isinstance(self.__value_raw, (str, bytes)):
248
275
  raise OrionisEnvironmentValueError(
249
276
  f"Value must be a string or bytes to convert to Base64, got {type(self.__value_raw).__name__} instead."
@@ -257,141 +284,147 @@ class EnvironmentCaster(IEnvironmentCaster):
257
284
 
258
285
  def __parseBase64(self) -> str:
259
286
  """
260
- Decodes the Base64 encoded value, assuming the type hint is 'base64:'.
287
+ Decode the internal raw value from Base64 encoding.
261
288
 
262
- This method decodes the internal raw value from Base64 and returns it as a string.
263
- If the value cannot be decoded, an `OrionisEnvironmentValueException` is raised.
289
+ Decodes the Base64-encoded string stored in the internal raw value and returns the decoded result as a string.
290
+ If decoding fails, raises an OrionisEnvironmentValueException.
264
291
 
265
292
  Returns
266
293
  -------
267
294
  str
268
- The decoded Base64 value as a string.
295
+ The decoded string from the Base64-encoded internal value.
269
296
 
270
297
  Raises
271
298
  ------
272
299
  OrionisEnvironmentValueException
273
- If the value cannot be decoded from Base64.
300
+ If the internal value cannot be decoded from Base64.
274
301
  """
302
+
303
+ # Import the base64 module for decoding
275
304
  import base64
276
305
 
277
306
  try:
278
- # Decode the Base64 encoded value
307
+
308
+ # Decode the Base64 encoded value and return as string
279
309
  decoded_value = base64.b64decode(self.__value_raw).decode()
280
310
  return decoded_value
311
+
281
312
  except Exception as e:
313
+
314
+ # Raise a custom exception if decoding fails
282
315
  raise OrionisEnvironmentValueException(f"Cannot decode Base64 value '{self.__value_raw}': {str(e)}")
283
316
 
284
317
  def __parsePath(self):
285
318
  """
286
- Converts the internal raw value to a `Path` object, assuming the type hint is 'path:'.
287
-
288
- This method processes the internal value as a file system path. It replaces backslashes
289
- with forward slashes for normalization and returns a `Path` object representing the path.
319
+ Convert the internal raw value to a normalized POSIX path string.
290
320
 
291
- Parameters
292
- ----------
293
- self : EnvironmentCaster
294
- The instance of the EnvironmentCaster class.
321
+ This method processes the internal value as a file system path. If the value is already
322
+ a `Path` object, it returns its POSIX representation. If the value is a string, it replaces
323
+ backslashes with forward slashes for normalization and returns the POSIX path string.
295
324
 
296
325
  Returns
297
326
  -------
298
- pathlib.Path
299
- A `Path` object representing the normalized file system path.
327
+ str
328
+ The normalized POSIX path string representing the file system path.
300
329
 
301
330
  Raises
302
331
  ------
303
332
  OrionisEnvironmentValueException
304
333
  If the value cannot be processed as a valid path.
305
334
  """
335
+
336
+ # Import the Path class from pathlib for path manipulation
306
337
  from pathlib import Path
307
338
 
308
- # If the value is already a Path object, return it directly
339
+ # If the value is already a Path object, return its POSIX representation
309
340
  if isinstance(self.__value_raw, Path):
310
341
  return self.__value_raw.as_posix()
311
342
 
312
343
  # Normalize the path by replacing backslashes with forward slashes
313
344
  normalized_path = str(self.__value_raw).replace('\\', '/')
314
345
 
315
- # Avoid redundant wrapping: if normalized_path is already absolute, just return Path(normalized_path)
346
+ # Convert the normalized string to a Path object and return its POSIX representation
316
347
  return Path(normalized_path).as_posix()
317
348
 
318
349
  def __toPath(self) -> str:
319
350
  """
320
- Converts the internal value to an absolute path string.
351
+ Convert the internal value to an absolute POSIX path string with type hint prefix.
321
352
 
322
353
  Returns
323
354
  -------
324
355
  str
325
- A string representing the type hint and the absolute path value.
356
+ A string in the format "<type_hint>:<absolute_path>", where <absolute_path> is the
357
+ normalized, absolute POSIX path representation of the internal value.
326
358
 
327
359
  Raises
328
360
  ------
329
361
  OrionisEnvironmentValueError
330
- If the internal value is not a string or Path.
362
+ If the internal value is not a string or a pathlib.Path object.
331
363
  """
364
+
365
+ # Import the Path class from pathlib for path manipulation
332
366
  from pathlib import Path
333
- import os
334
367
 
368
+ # Ensure the internal value is a string or Path object
335
369
  if not isinstance(self.__value_raw, (str, Path)):
336
370
  raise OrionisEnvironmentValueError(
337
- f"Value must be a string or Path to convert to path, got {type(self.__value_raw).__name__} instead."
371
+ f"Value must be a string or Path to convert to path, got {type(self.__value_raw).__name__} instead."
338
372
  )
339
373
 
340
- # Normalize slashes and strip whitespace
374
+ # Normalize slashes and strip whitespace from the path string
341
375
  raw_path = str(self.__value_raw).replace('\\', '/').strip()
342
376
 
343
- # If the path is relative, resolve it from the current working directory
377
+ # Create a Path object from the normalized path string
344
378
  path_obj = Path(raw_path)
345
379
 
346
- # If the path is not absolute, make it absolute by combining with the current working directory
380
+ # If the path is not absolute, resolve it relative to the current working directory
347
381
  if not path_obj.is_absolute():
348
382
 
349
- # Remove leading slash if present to avoid absolute path when joining
383
+ # Remove any leading slash to avoid creating an absolute path when joining
350
384
  raw_path_no_leading = raw_path.lstrip('/\\')
385
+
386
+ # Combine with the current working directory to form an absolute path
351
387
  path_obj = Path(Path.cwd()) / raw_path_no_leading
352
388
 
353
- # Resolve the path to get the absolute path
389
+ # Expand user home and convert to POSIX format for consistency
354
390
  abs_path = path_obj.expanduser().as_posix()
355
391
 
356
- # Return the absolute path as a string with the type hint
392
+ # Return the absolute path as a string with the type hint prefix
357
393
  return f"{self.__type_hint}:{str(abs_path)}"
358
394
 
359
395
  def __parseStr(self):
360
396
  """
361
- Returns the value as a string, assuming the type hint is 'str:'.
397
+ Returns the internal raw value as a string, removing leading whitespace.
362
398
 
363
- This method processes the internal raw value and returns it as a string,
364
- provided the type hint is 'str:'. Leading whitespace is removed from the value
365
- before returning. No type conversion is performed; the value is returned as-is
366
- after stripping leading whitespace.
399
+ Parameters
400
+ ----------
401
+ self : EnvironmentCaster
402
+ Instance of the EnvironmentCaster class.
367
403
 
368
404
  Returns
369
405
  -------
370
406
  str
371
407
  The internal value as a string with leading whitespace removed.
372
408
 
373
- Raises
374
- ------
375
- None
376
- This method does not raise any exceptions.
409
+ Notes
410
+ -----
411
+ No type conversion is performed; the value is returned as a string after
412
+ stripping leading whitespace. This method assumes the type hint is 'str:'.
413
+ No exceptions are raised by this method.
377
414
  """
378
415
 
379
- # Return the internal value as a string, removing leading whitespace
416
+ # Remove leading whitespace from the internal value
417
+ # This ensures that any accidental spaces before the value are ignored
380
418
  return self.__value_raw.lstrip()
381
419
 
382
420
  def __toStr(self):
383
421
  """
384
- Converts the internal value to a string representation with the type hint prefix.
385
-
386
- This method checks if the internal value is a string. If so, it returns a string
387
- in the format "<type_hint>:<value>", where <type_hint> is the current type hint
388
- and <value> is the internal string value. If the internal value is not a string,
389
- an exception is raised.
422
+ Returns the internal value as a string representation with the type hint prefix.
390
423
 
391
424
  Returns
392
425
  -------
393
426
  str
394
- A string combining the type hint and the internal value, separated by a colon.
427
+ The string representation of the internal value, prefixed by the type hint and separated by a colon.
395
428
 
396
429
  Raises
397
430
  ------
@@ -401,25 +434,21 @@ class EnvironmentCaster(IEnvironmentCaster):
401
434
 
402
435
  # Ensure the internal value is a string before conversion
403
436
  if not isinstance(self.__value_raw, str):
437
+
438
+ # Raise an error if the value is not a string
404
439
  raise OrionisEnvironmentValueError(
405
440
  f"Value must be a string to convert to str, got {type(self.__value_raw).__name__} instead."
406
441
  )
407
442
 
408
443
  # Return the formatted string with type hint and value
409
- return f"{self.__value_raw}"
444
+ return f"{self.__type_hint}:{self.__value_raw}"
410
445
 
411
446
  def __parseInt(self):
412
447
  """
413
- Converts the internal raw value to an integer, assuming the type hint is 'int:'.
414
-
415
- This method attempts to strip leading and trailing whitespace from the internal
416
- raw value and convert it to an integer. If the conversion fails due to an invalid
417
- format or non-integer input, an `OrionisEnvironmentValueException` is raised.
448
+ Convert the internal raw value to an integer.
418
449
 
419
- Parameters
420
- ----------
421
- self : EnvironmentCaster
422
- The instance of the EnvironmentCaster class.
450
+ Strips leading and trailing whitespace from the internal raw value and attempts to convert it to an integer.
451
+ Raises an OrionisEnvironmentValueException if the conversion fails due to invalid format or type.
423
452
 
424
453
  Returns
425
454
  -------
@@ -431,13 +460,13 @@ class EnvironmentCaster(IEnvironmentCaster):
431
460
  OrionisEnvironmentValueException
432
461
  If the value cannot be converted to an integer due to invalid format or type.
433
462
  """
463
+
434
464
  # Remove leading and trailing whitespace from the raw value
435
465
  value = self.__value_raw.strip()
436
466
 
437
467
  # Attempt to convert the value to an integer
438
468
  try:
439
469
  return int(value)
440
-
441
470
  # Raise a custom exception if conversion fails
442
471
  except ValueError as e:
443
472
  raise OrionisEnvironmentValueException(f"Cannot convert '{value}' to int: {str(e)}")
@@ -446,14 +475,11 @@ class EnvironmentCaster(IEnvironmentCaster):
446
475
  """
447
476
  Converts the internal value to a string representation with the integer type hint prefix.
448
477
 
449
- This method checks if the internal value is an integer. If so, it returns a string
450
- in the format "<type_hint>:<value>", where <type_hint> is the current type hint
451
- and <value> is the integer value. If the internal value is not an integer, an exception is raised.
452
-
453
478
  Returns
454
479
  -------
455
480
  str
456
- A string combining the type hint and the internal integer value, separated by a colon.
481
+ String in the format "<type_hint>:<value>", where <type_hint> is the current type hint
482
+ and <value> is the integer value.
457
483
 
458
484
  Raises
459
485
  ------
@@ -461,8 +487,10 @@ class EnvironmentCaster(IEnvironmentCaster):
461
487
  If the internal value is not an integer.
462
488
  """
463
489
 
464
- # Ensure the internal value is an integer before conversion
490
+ # Check if the internal value is an integer before conversion
465
491
  if not isinstance(self.__value_raw, int):
492
+
493
+ # Raise an error if the value is not an integer
466
494
  raise OrionisEnvironmentValueError(
467
495
  f"Value must be an integer to convert to int, got {type(self.__value_raw).__name__} instead."
468
496
  )
@@ -472,16 +500,10 @@ class EnvironmentCaster(IEnvironmentCaster):
472
500
 
473
501
  def __parseFloat(self):
474
502
  """
475
- Converts the internal raw value to a float, assuming the type hint is 'float:'.
503
+ Convert the internal raw value to a float.
476
504
 
477
- This method attempts to strip leading and trailing whitespace from the internal
478
- raw value and convert it to a float. If the conversion fails due to an invalid
479
- format or non-numeric input, an `OrionisEnvironmentValueException` is raised.
480
-
481
- Parameters
482
- ----------
483
- self : EnvironmentCaster
484
- The instance of the EnvironmentCaster class.
505
+ Strips leading and trailing whitespace from the internal raw value and attempts to convert it to a float.
506
+ Raises an OrionisEnvironmentValueException if the conversion fails due to invalid format or type.
485
507
 
486
508
  Returns
487
509
  -------
@@ -493,7 +515,8 @@ class EnvironmentCaster(IEnvironmentCaster):
493
515
  OrionisEnvironmentValueException
494
516
  If the value cannot be converted to a float due to invalid format or type.
495
517
  """
496
- # Remove leading and trailing whitespace from the raw value
518
+
519
+ # Remove leading and trailing whitespace from the raw value to ensure clean input
497
520
  value = self.__value_raw.strip()
498
521
 
499
522
  # Attempt to convert the value to a float
@@ -508,15 +531,11 @@ class EnvironmentCaster(IEnvironmentCaster):
508
531
  """
509
532
  Converts the internal value to a string representation with the float type hint prefix.
510
533
 
511
- This method checks if the internal value is a float. If so, it returns a string
512
- in the format "<type_hint>:<value>", where <type_hint> is the current type hint
513
- and <value> is the float value. If the internal value is not a float, an exception is raised.
514
-
515
534
  Returns
516
535
  -------
517
536
  str
518
- A string combining the type hint and the internal float value, separated by a colon.
519
- For example, "float:3.14".
537
+ A string in the format "<type_hint>:<value>", where <type_hint> is the current type hint
538
+ and <value> is the float value.
520
539
 
521
540
  Raises
522
541
  ------
@@ -526,6 +545,8 @@ class EnvironmentCaster(IEnvironmentCaster):
526
545
 
527
546
  # Ensure the internal value is a float before conversion
528
547
  if not isinstance(self.__value_raw, float):
548
+
549
+ # Raise an error if the value is not a float
529
550
  raise OrionisEnvironmentValueError(
530
551
  f"Value must be a float to convert to float, got {type(self.__value_raw).__name__} instead."
531
552
  )
@@ -535,23 +556,17 @@ class EnvironmentCaster(IEnvironmentCaster):
535
556
 
536
557
  def __parseBool(self):
537
558
  """
538
- Converts the internal raw value to a boolean, assuming the type hint is 'bool:'.
539
-
540
- This method processes the internal raw value by stripping leading and trailing whitespace,
541
- converting it to lowercase, and then checking if it matches the string 'true' or 'false'.
542
- If the value is 'true', it returns the boolean value True. If the value is 'false', it returns
543
- the boolean value False. If the value does not match either, an `OrionisEnvironmentValueException`
544
- is raised.
559
+ Convert the internal raw value to a boolean.
545
560
 
546
- Parameters
547
- ----------
548
- self : EnvironmentCaster
549
- The instance of the EnvironmentCaster class.
561
+ This method strips leading and trailing whitespace from the internal raw value,
562
+ converts it to lowercase, and checks if it matches 'true' or 'false'. If the value
563
+ is 'true', it returns True. If the value is 'false', it returns False. If the value
564
+ does not match either, an OrionisEnvironmentValueException is raised.
550
565
 
551
566
  Returns
552
567
  -------
553
568
  bool
554
- Returns True if the value is 'true' (case-insensitive), False if the value is 'false' (case-insensitive).
569
+ True if the value is 'true' (case-insensitive), False if the value is 'false' (case-insensitive).
555
570
 
556
571
  Raises
557
572
  ------
@@ -559,35 +574,30 @@ class EnvironmentCaster(IEnvironmentCaster):
559
574
  If the value cannot be converted to a boolean because it does not match 'true' or 'false'.
560
575
  """
561
576
 
562
- # Strip whitespace and convert the value to lowercase for comparison
577
+ # Remove leading and trailing whitespace, then convert to lowercase for comparison
563
578
  value = self.__value_raw.strip().lower()
564
579
 
565
- # Check for 'true' and return True
580
+ # If the value is 'true', return True
566
581
  if value == 'true':
567
582
  return True
568
583
 
569
- # Check for 'false' and return False
584
+ # If the value is 'false', return False
570
585
  elif value == 'false':
571
586
  return False
572
587
 
573
- # Raise an exception if the value cannot be interpreted as a boolean
588
+ # If the value is neither 'true' nor 'false', raise an exception
574
589
  else:
575
590
  raise OrionisEnvironmentValueException(f"Cannot convert '{value}' to bool.")
576
591
 
577
592
  def __toBool(self):
578
593
  """
579
- Converts the internal value to a string representation with the boolean type hint prefix.
580
-
581
- This method checks if the internal value is a boolean. If so, it returns a string
582
- in the format "<type_hint>:<value>", where <type_hint> is the current type hint
583
- and <value> is the lowercase string representation of the boolean value.
584
- If the internal value is not a boolean, an exception is raised.
594
+ Convert the internal value to a string representation with the boolean type hint prefix.
585
595
 
586
596
  Returns
587
597
  -------
588
598
  str
589
- A string combining the type hint and the internal boolean value, separated by a colon.
590
- The boolean value is represented as 'true' or 'false' in lowercase.
599
+ A string in the format "<type_hint>:<value>", where <type_hint> is the current type hint
600
+ and <value> is the lowercase string representation of the boolean value ('true' or 'false').
591
601
 
592
602
  Raises
593
603
  ------
@@ -597,6 +607,8 @@ class EnvironmentCaster(IEnvironmentCaster):
597
607
 
598
608
  # Ensure the internal value is a boolean before conversion
599
609
  if not isinstance(self.__value_raw, bool):
610
+
611
+ # Raise an error if the value is not a boolean
600
612
  raise OrionisEnvironmentValueError(
601
613
  f"Value must be a boolean to convert to bool, got {type(self.__value_raw).__name__} instead."
602
614
  )
@@ -606,43 +618,41 @@ class EnvironmentCaster(IEnvironmentCaster):
606
618
 
607
619
  def __parseList(self):
608
620
  """
609
- Converts the internal raw value to a list, assuming the type hint is 'list:'.
621
+ Parses the internal raw value and converts it to a Python list.
610
622
 
611
- This method attempts to strip leading and trailing whitespace from the internal
612
- raw value and convert it to a Python list using `ast.literal_eval`. If the conversion
613
- fails due to an invalid format or if the evaluated value is not a list, an
623
+ The method strips leading and trailing whitespace from the internal raw value,
624
+ then attempts to safely evaluate the string as a Python list using `ast.literal_eval`.
625
+ If the conversion is successful and the result is a list, it is returned.
626
+ If the conversion fails or the evaluated value is not a list, an
614
627
  `OrionisEnvironmentValueException` is raised.
615
628
 
616
- Parameters
617
- ----------
618
- self : EnvironmentCaster
619
- The instance of the EnvironmentCaster class.
620
-
621
629
  Returns
622
630
  -------
623
631
  list
624
- The internal value converted to a list if the type hint is 'list:'.
632
+ The internal value converted to a list.
625
633
 
626
634
  Raises
627
635
  ------
628
636
  OrionisEnvironmentValueException
629
637
  If the value cannot be converted to a list due to invalid format or type.
630
638
  """
639
+
640
+ # Import the ast module for safe evaluation of string literals
631
641
  import ast
632
642
 
633
- # Remove leading and trailing whitespace from the raw value
643
+ # Remove leading and trailing whitespace from the raw value to ensure clean input
634
644
  value = self.__value_raw.strip()
635
645
 
636
646
  try:
637
647
 
638
- # Safely evaluate the string to a Python object
648
+ # Safely evaluate the string to a Python object using ast.literal_eval
639
649
  parsed = ast.literal_eval(value)
640
650
 
641
651
  # Ensure the evaluated object is a list
642
652
  if not isinstance(parsed, list):
643
653
  raise ValueError("Value is not a list")
644
654
 
645
- # Return the parsed list
655
+ # Return the parsed list if successful
646
656
  return parsed
647
657
 
648
658
  except (ValueError, SyntaxError) as e:
@@ -652,18 +662,18 @@ class EnvironmentCaster(IEnvironmentCaster):
652
662
 
653
663
  def __toList(self):
654
664
  """
655
- Converts the internal value to a string representation with the list type hint prefix.
665
+ Converts the internal value to its string representation with the list type hint prefix.
656
666
 
657
- This method checks if the internal value is a list. If so, it returns a string
658
- in the format "<type_hint>:<value>", where <type_hint> is the current type hint
659
- and <value> is the string representation of the list. If the internal value is not a list,
660
- an exception is raised.
667
+ Parameters
668
+ ----------
669
+ self : EnvironmentCaster
670
+ Instance of the EnvironmentCaster class.
661
671
 
662
672
  Returns
663
673
  -------
664
674
  str
665
- A string combining the type hint and the internal list value, separated by a colon.
666
- For example, "list:[1, 2, 3]".
675
+ A string in the format "<type_hint>:<value>", where <type_hint> is the current type hint
676
+ and <value> is the string representation of the list.
667
677
 
668
678
  Raises
669
679
  ------
@@ -673,6 +683,8 @@ class EnvironmentCaster(IEnvironmentCaster):
673
683
 
674
684
  # Ensure the internal value is a list before conversion
675
685
  if not isinstance(self.__value_raw, list):
686
+
687
+ # Raise an error if the value is not a list
676
688
  raise OrionisEnvironmentValueError(
677
689
  f"Value must be a list to convert to list, got {type(self.__value_raw).__name__} instead."
678
690
  )
@@ -682,43 +694,42 @@ class EnvironmentCaster(IEnvironmentCaster):
682
694
 
683
695
  def __parseDict(self):
684
696
  """
685
- Converts the internal raw value to a dictionary, assuming the type hint is 'dict:'.
686
-
687
- This method attempts to strip leading and trailing whitespace from the internal
688
- raw value and safely evaluate it as a Python dictionary using `ast.literal_eval`.
689
- If the conversion fails due to an invalid format or if the evaluated value is not
690
- a dictionary, an `OrionisEnvironmentValueException` is raised.
697
+ Parses the internal raw value and converts it to a Python dictionary.
691
698
 
692
- Parameters
693
- ----------
694
- self : EnvironmentCaster
695
- The instance of the EnvironmentCaster class.
699
+ The method strips leading and trailing whitespace from the internal raw value,
700
+ then attempts to safely evaluate the string as a Python dictionary using
701
+ `ast.literal_eval`. If the conversion is successful and the result is a dictionary,
702
+ it is returned. If the conversion fails or the evaluated value is not a dictionary,
703
+ an OrionisEnvironmentValueException is raised.
696
704
 
697
705
  Returns
698
706
  -------
699
707
  dict
700
- The internal value converted to a dictionary if the type hint is 'dict:'.
708
+ The internal value converted to a dictionary.
701
709
 
702
710
  Raises
703
711
  ------
704
712
  OrionisEnvironmentValueException
705
713
  If the value cannot be converted to a dictionary due to invalid format or type.
706
714
  """
715
+
716
+ # Import the ast module for safe evaluation of string literals
707
717
  import ast
708
718
 
709
- # Remove leading and trailing whitespace from the raw value
719
+ # Remove leading and trailing whitespace from the raw value to ensure clean input
710
720
  value = self.__value_raw.strip()
711
721
 
722
+ # Attempt to parse the string as a dictionary
712
723
  try:
713
724
 
714
- # Safely evaluate the string to a Python object
725
+ # Safely evaluate the string to a Python object using ast.literal_eval
715
726
  parsed = ast.literal_eval(value)
716
727
 
717
728
  # Ensure the evaluated object is a dictionary
718
729
  if not isinstance(parsed, dict):
719
730
  raise ValueError("Value is not a dict")
720
731
 
721
- # Return the parsed dictionary
732
+ # Return the parsed dictionary if successful
722
733
  return parsed
723
734
 
724
735
  except (ValueError, SyntaxError) as e:
@@ -730,16 +741,11 @@ class EnvironmentCaster(IEnvironmentCaster):
730
741
  """
731
742
  Converts the internal value to a string representation with the dictionary type hint prefix.
732
743
 
733
- This method checks if the internal value is a dictionary. If so, it returns a string
734
- in the format "<type_hint>:<value>", where <type_hint> is the current type hint
735
- and <value> is the string representation of the dictionary. If the internal value is not a dictionary,
736
- an exception is raised.
737
-
738
744
  Returns
739
745
  -------
740
746
  str
741
- A string combining the type hint and the internal dictionary value, separated by a colon.
742
- For example, "dict:{'key': 'value'}".
747
+ A string in the format "<type_hint>:<value>", where <type_hint> is the current type hint
748
+ and <value> is the string representation of the dictionary.
743
749
 
744
750
  Raises
745
751
  ------
@@ -749,6 +755,8 @@ class EnvironmentCaster(IEnvironmentCaster):
749
755
 
750
756
  # Ensure the internal value is a dictionary before conversion
751
757
  if not isinstance(self.__value_raw, dict):
758
+
759
+ # Raise an error if the value is not a dictionary
752
760
  raise OrionisEnvironmentValueError(
753
761
  f"Value must be a dict to convert to dict, got {type(self.__value_raw).__name__} instead."
754
762
  )
@@ -758,44 +766,41 @@ class EnvironmentCaster(IEnvironmentCaster):
758
766
 
759
767
  def __parseTuple(self):
760
768
  """
761
- Converts the internal raw value to a tuple, assuming the type hint is 'tuple:'.
769
+ Parse the internal raw value and convert it to a Python tuple.
762
770
 
763
- This method strips leading and trailing whitespace from the internal raw value,
771
+ The method removes leading and trailing whitespace from the internal raw value,
764
772
  then attempts to safely evaluate the string as a Python tuple using `ast.literal_eval`.
765
773
  If the conversion is successful and the result is a tuple, it is returned.
766
774
  If the conversion fails or the evaluated value is not a tuple, an
767
- `OrionisEnvironmentValueException` is raised.
768
-
769
- Parameters
770
- ----------
771
- self : EnvironmentCaster
772
- The instance of the EnvironmentCaster class.
775
+ OrionisEnvironmentValueException is raised.
773
776
 
774
777
  Returns
775
778
  -------
776
779
  tuple
777
- The internal value converted to a tuple if the type hint is 'tuple:'.
780
+ The internal value converted to a tuple.
778
781
 
779
782
  Raises
780
783
  ------
781
784
  OrionisEnvironmentValueException
782
785
  If the value cannot be converted to a tuple due to invalid format or type.
783
786
  """
787
+
788
+ # Import the ast module for safe evaluation of string literals
784
789
  import ast
785
790
 
786
- # Remove leading and trailing whitespace from the raw value
791
+ # Remove leading and trailing whitespace from the raw value to ensure clean input
787
792
  value = self.__value_raw.strip()
788
793
 
789
794
  try:
790
795
 
791
- # Safely evaluate the string to a Python object
796
+ # Safely evaluate the string to a Python object using ast.literal_eval
792
797
  parsed = ast.literal_eval(value)
793
798
 
794
799
  # Ensure the evaluated object is a tuple
795
800
  if not isinstance(parsed, tuple):
796
801
  raise ValueError("Value is not a tuple")
797
802
 
798
- # Return the parsed tuple
803
+ # Return the parsed tuple if successful
799
804
  return parsed
800
805
 
801
806
  except (ValueError, SyntaxError) as e:
@@ -805,18 +810,13 @@ class EnvironmentCaster(IEnvironmentCaster):
805
810
 
806
811
  def __toTuple(self):
807
812
  """
808
- Converts the internal value to a string representation with the tuple type hint prefix.
809
-
810
- This method checks if the internal value is a tuple. If so, it returns a string
811
- in the format "<type_hint>:<value>", where <type_hint> is the current type hint
812
- and <value> is the string representation of the tuple. If the internal value is not a tuple,
813
- an exception is raised.
813
+ Convert the internal value to a string representation with the tuple type hint prefix.
814
814
 
815
815
  Returns
816
816
  -------
817
817
  str
818
- A string combining the type hint and the internal tuple value, separated by a colon.
819
- For example, "tuple:(1, 2, 3)".
818
+ A string in the format "<type_hint>:<value>", where <type_hint> is the current type hint
819
+ and <value> is the string representation of the tuple.
820
820
 
821
821
  Raises
822
822
  ------
@@ -826,6 +826,8 @@ class EnvironmentCaster(IEnvironmentCaster):
826
826
 
827
827
  # Ensure the internal value is a tuple before conversion
828
828
  if not isinstance(self.__value_raw, tuple):
829
+
830
+ # Raise an error if the value is not a tuple
829
831
  raise OrionisEnvironmentValueError(
830
832
  f"Value must be a tuple to convert to tuple, got {type(self.__value_raw).__name__} instead."
831
833
  )
@@ -835,39 +837,41 @@ class EnvironmentCaster(IEnvironmentCaster):
835
837
 
836
838
  def __parseSet(self):
837
839
  """
838
- Converts the internal raw value to a set, assuming the type hint is 'set:'.
840
+ Parse the internal raw value and convert it to a Python set.
839
841
 
840
- This method strips leading and trailing whitespace from the internal raw value,
842
+ This method removes leading and trailing whitespace from the internal raw value,
841
843
  then attempts to safely evaluate the string as a Python set using `ast.literal_eval`.
842
844
  If the conversion is successful and the result is a set, it is returned.
843
845
  If the conversion fails or the evaluated value is not a set, an
844
- `OrionisEnvironmentValueException` is raised.
846
+ OrionisEnvironmentValueException is raised.
845
847
 
846
848
  Returns
847
849
  -------
848
850
  set
849
- The internal value converted to a set if the type hint is 'set:'.
851
+ The internal value converted to a set.
850
852
 
851
853
  Raises
852
854
  ------
853
855
  OrionisEnvironmentValueException
854
856
  If the value cannot be converted to a set due to invalid format or type.
855
857
  """
858
+
859
+ # Import the ast module for safe evaluation of string literals
856
860
  import ast
857
861
 
858
- # Remove leading and trailing whitespace from the raw value
862
+ # Remove leading and trailing whitespace from the raw value to ensure clean input
859
863
  value = self.__value_raw.strip()
860
864
 
861
865
  try:
862
866
 
863
- # Safely evaluate the string to a Python object
867
+ # Safely evaluate the string to a Python object using ast.literal_eval
864
868
  parsed = ast.literal_eval(value)
865
869
 
866
870
  # Ensure the evaluated object is a set
867
871
  if not isinstance(parsed, set):
868
872
  raise ValueError("Value is not a set")
869
873
 
870
- # Return the parsed set
874
+ # Return the parsed set if successful
871
875
  return parsed
872
876
 
873
877
  except (ValueError, SyntaxError) as e:
@@ -877,18 +881,13 @@ class EnvironmentCaster(IEnvironmentCaster):
877
881
 
878
882
  def __toSet(self):
879
883
  """
880
- Converts the internal value to a string representation with the set type hint prefix.
881
-
882
- This method checks if the internal value is a set. If so, it returns a string
883
- in the format "<type_hint>:<value>", where <type_hint> is the current type hint
884
- and <value> is the string representation of the set. If the internal value is not a set,
885
- an exception is raised.
884
+ Convert the internal value to a string representation with the set type hint prefix.
886
885
 
887
886
  Returns
888
887
  -------
889
888
  str
890
- A string combining the type hint and the internal set value, separated by a colon.
891
- For example, "set:{1, 2, 3}".
889
+ A string in the format "<type_hint>:<value>", where <type_hint> is the current type hint
890
+ and <value> is the string representation of the set.
892
891
 
893
892
  Raises
894
893
  ------
@@ -898,8 +897,9 @@ class EnvironmentCaster(IEnvironmentCaster):
898
897
 
899
898
  # Ensure the internal value is a set before conversion
900
899
  if not isinstance(self.__value_raw, set):
900
+ # Raise an error if the value is not a set
901
901
  raise OrionisEnvironmentValueError(
902
- f"Value must be a set to convert to set, got {type(self.__value_raw).__name__} instead."
902
+ f"Value must be a set to convert to set, got {type(self.__value_raw).__name__} instead."
903
903
  )
904
904
 
905
905
  # Return the formatted string with type hint and set value