@@ -522,8 +522,8 @@ def _dict_value(self, syntax, key, value):
522522 raise DeclError (f"Unknown { key } keys: { ', ' .join (unknown_keys )} " )
523523
524524 # Iterate over the keys defined in syntax. If the subvalue or default
525- # value is defined, set it or raise error if required .
526- for subkey , subkey_format in syntax .items ():
525+ # value is defined, set it.
526+ for subkey in syntax .keys ():
527527 subkey_value = value .get (subkey ,
528528 Config ._syntax_default (syntax , subkey ))
529529 if subkey_value is not None :
@@ -533,12 +533,7 @@ def _dict_value(self, syntax, key, value):
533533 subkey_value ,
534534 syntax [subkey ].get ('check' , 'string' )
535535 )
536- elif subkey_format .get ('required' , False ):
537- raise DeclError (
538- f"Key { subkey } is required in dict parameter { key } "
539- )
540536
541- # Set the key in options dict eventually.
542537 return result
543538
544539 def _record_value (self , syntax , value ):
@@ -585,22 +580,45 @@ def update(self, data):
585580 self .set (key , value , arch = arch )
586581
587582 def _check (self ):
588- """Checks for mandatory options."""
589- for key , value in self .SYNTAX .items ():
583+ """Checks for required options in main syntax recursively."""
584+ self ._check_syntax (self .SYNTAX , self .options )
585+
586+ def _check_syntax (self , syntax , options , param = '__main__' ):
587+ """Checks for mandatory options regarding the provided syntax recursively."""
588+ for key in syntax :
590589 if (
591- value .get ('required' , False ) and
592- 'default' not in value
590+ syntax [ key ] .get ('required' , False ) and
591+ 'default' not in syntax [ key ]
593592 ):
594593 # Check key is in options or defined in all supported arch
595594 # specific options.
596595 if (
597- key not in self . options and
596+ key not in options and
598597 not all (
599- arch in self . options and key in self . options [arch ]
598+ arch in options and key in options [arch ]
600599 for arch in self .get ('arch' )
601600 )
602601 ):
603- raise DeclError (f"'{ key } ' is not defined" )
602+ if param == '__main__' :
603+ raise DeclError (f"'{ key } ' is not defined" )
604+ raise DeclError (
605+ f"Key { key } is required in dict parameter { param } "
606+ )
607+ # If the parameter is a dict with a syntax, check the value.
608+ if (
609+ syntax [key ].get ('check' ) == 'dict' and
610+ syntax [key ].get ('syntax' ) is not None and key in options
611+ ):
612+ self ._check_syntax (syntax [key ]['syntax' ], options [key ], key )
613+ # If the parameter is a record with dict values and a syntax, check
614+ # all values.
615+ if (
616+ syntax [key ].get ('check' ) == 'record' and
617+ syntax [key ].get ('content' ) == 'dict' and
618+ syntax [key ].get ('syntax' ) is not None and key in options
619+ ):
620+ for value in options [key ].values ():
621+ self ._check_syntax (syntax [key ]['syntax' ], value , key )
604622
605623
606624class Staff ():
0 commit comments