@@ -82,11 +82,7 @@ def __hash__(self) -> int:
82
82
return hash (deep_freeze (self .wildcards ))
83
83
84
84
def __sizeof__ (self ):
85
- return (
86
- self .wildcards .__sizeof__ ()
87
- + self .__wildcards_folders .__sizeof__ ()
88
- + self .__wildcard_files .__sizeof__ ()
89
- )
85
+ return self .wildcards .__sizeof__ () + self .__wildcards_folders .__sizeof__ () + self .__wildcard_files .__sizeof__ ()
90
86
91
87
def refresh_wildcards (self , debug_level : DEBUG_LEVEL , wildcards_folders : Optional [list [str ]]):
92
88
"""
@@ -245,51 +241,60 @@ def __get_choices(self, obj: object, full_path: str, key_parts: list[str]) -> li
245
241
Returns:
246
242
list: list of choices
247
243
"""
248
- choices = None
249
- if obj is not None :
250
- if isinstance (obj , (str , dict )):
251
- choices = [obj ]
252
- elif isinstance (obj , (int , float , bool )):
253
- choices = [str (obj )]
254
- elif isinstance (obj , list ) and len (obj ) > 0 :
255
- choices = []
256
- for i , c in enumerate (obj ):
257
- invalid_choice = False
258
- if isinstance (c , str ):
259
- choice = c
260
- elif isinstance (c , (int , float , bool )):
261
- choice = str (c )
262
- elif isinstance (c , list ):
263
- # we create an anonymous wildcard
264
- choice = self .__create_anonymous_wildcard (full_path , key_parts , i , c )
265
- elif isinstance (c , dict ):
266
- if self .is_dict_choices_options (c ) or self .is_dict_choice_options (c ):
267
- # we assume it is a choice or wildcard parameters in object format
268
- choice = c
269
- choice_content = choice .get ("content" , choice .get ("text" , None ))
270
- if choice_content is not None and isinstance (choice_content , list ):
271
- # we create an anonymous wildcard
272
- choice ["content" ] = self .__create_anonymous_wildcard (
273
- full_path , key_parts , i , choice_content
274
- )
275
- if "text" in choice :
276
- del choice ["text" ]
277
- elif len (c ) == 1 :
278
- # we assume it is an anonymous wildcard with options
279
- firstkey = list (c .keys ())[0 ]
280
- choice = self .__create_anonymous_wildcard (full_path , key_parts , i , c [firstkey ], firstkey )
281
- else :
282
- invalid_choice = True
283
- else :
284
- invalid_choice = True
285
- if invalid_choice :
286
- self .__logger .warning (
287
- f"Invalid choice { i + 1 } in wildcard '{ '/' .join (key_parts )} ' in file '{ full_path } '!"
288
- )
289
- else :
290
- choices .append (choice )
244
+ if obj is None :
245
+ return None
246
+ if isinstance (obj , (str , dict )):
247
+ return [obj ]
248
+ if isinstance (obj , (int , float , bool )):
249
+ return [str (obj )]
250
+ if not isinstance (obj , list ) or len (obj ) == 0 :
251
+ self .__logger .warning (f"Invalid format in wildcard '{ '/' .join (key_parts )} ' in file '{ full_path } '!" )
252
+ return None
253
+ choices = []
254
+ for i , c in enumerate (obj ):
255
+ if isinstance (c , (str , int , float , bool )):
256
+ choices .append (str (c ))
257
+ elif isinstance (c , list ):
258
+ # we create an anonymous wildcard
259
+ choices .append (self .__create_anonymous_wildcard (full_path , key_parts , i , c ))
260
+ elif isinstance (c , dict ):
261
+ choices .append (self .__process_dict_choice (c , full_path , key_parts , i ))
262
+ else :
263
+ self .__logger .warning (
264
+ f"Invalid choice { i + 1 } in wildcard '{ '/' .join (key_parts )} ' in file '{ full_path } '!"
265
+ )
291
266
return choices
292
267
268
+ def __process_dict_choice (self , c : dict , full_path : str , key_parts : list [str ], i : int ) -> dict :
269
+ """
270
+ Process a dictionary choice.
271
+
272
+ Args:
273
+ c (dict): The dictionary choice.
274
+ full_path (str): The path to the file.
275
+ key_parts (list[str]): The parts of the key.
276
+ i (int): The index of the choice.
277
+
278
+ Returns:
279
+ dict: The processed choice.
280
+ """
281
+ if self .is_dict_choices_options (c ) or self .is_dict_choice_options (c ):
282
+ # we assume it is a choice or wildcard parameters in object format
283
+ choice = c
284
+ choice_content = choice .get ("content" , choice .get ("text" , None ))
285
+ if choice_content is not None and isinstance (choice_content , list ):
286
+ # we create an anonymous wildcard
287
+ choice ["content" ] = self .__create_anonymous_wildcard (full_path , key_parts , i , choice_content )
288
+ if "text" in choice :
289
+ del choice ["text" ]
290
+ return choice
291
+ if len (c ) == 1 :
292
+ # we assume it is an anonymous wildcard with options
293
+ firstkey = list (c .keys ())[0 ]
294
+ return self .__create_anonymous_wildcard (full_path , key_parts , i , c [firstkey ], firstkey )
295
+ self .__logger .warning (f"Invalid choice { i + 1 } in wildcard '{ '/' .join (key_parts )} ' in file '{ full_path } '!" )
296
+ return None
297
+
293
298
def __create_anonymous_wildcard (self , full_path , key_parts , i , content , options = None ):
294
299
"""
295
300
Create an anonymous wildcard.
0 commit comments