@@ -661,6 +661,11 @@ def make_static_initializer(entries: list, term_str: str = '') -> list:
661661
662662def load_schema (filename : str ) -> Database :
663663 def evaluate (expr : Any ) -> Any :
664+ if isinstance (expr , dict ):
665+ for k , v in expr .items ():
666+ if evaluate (k ):
667+ return v
668+ raise ValueError ("No choice match" )
664669 if isinstance (expr , list ):
665670 return [evaluate (v ) for v in expr ]
666671 if isinstance (expr , str ):
@@ -671,18 +676,26 @@ def evaluate(expr: Any) -> Any:
671676
672677 def calculate_props (props : dict , path : str ):
673678 new_props = {}
679+ keys_by_id = {}
674680 for key , value in props .items ():
675- if not key .startswith ('@' ):
676- new_props [key ] = value
677- continue
678- new_key = key [1 :]
679- new_path = f'{ path } /{ new_key } '
680- try :
681- new_value = evaluate (value )
682- except Exception as e :
683- raise ValueError (f'{ new_path } in "{ filename } "' ) from e
684- new_props [new_key ] = new_value
685- calc_props [new_path ] = new_value
681+ if key .startswith ('@' ):
682+ new_key = key [1 :]
683+ new_path = f'{ path } /{ new_key } '
684+ try :
685+ new_value = evaluate (value )
686+ except Exception as e :
687+ raise ValueError (f'{ new_path } in "{ filename } "' ) from e
688+ calc_props [new_path ] = new_value
689+ key = new_key
690+ value = new_value
691+ new_props [key ] = value
692+ id = make_identifier (key )
693+ if not id :
694+ raise ValueError (f'Invalid key "{ key } "' )
695+ key_conflict = keys_by_id .get (id )
696+ if key_conflict :
697+ raise ValueError (f'Key "{ key } " conflicts with "{ key_conflict } "' )
698+ keys_by_id [id ] = key
686699 props .clear ()
687700 props .update (new_props )
688701 for k , v in props .items ():
@@ -692,20 +705,8 @@ def calculate_props(props: dict, path: str):
692705
693706 '''Load JSON configuration schema and validate
694707 '''
695- def parse_object_pairs (pairs ):
696- d = {}
697- identifiers = set ()
698- for k , v in pairs :
699- id = make_identifier (k .removeprefix ('@' ))
700- if not id :
701- raise ValueError (f'Invalid key "{ k } "' )
702- if id in identifiers :
703- raise ValueError (f'Key "{ k } " produces duplicate identifier "{ id } "' )
704- identifiers .add (id )
705- d [k ] = v
706- return d
707708 with open (filename , 'r' , encoding = 'utf-8' ) as f :
708- schema = json .load (f , object_pairs_hook = parse_object_pairs )
709+ schema = json .load (f )
709710
710711 calculate_props (schema , '' )
711712
0 commit comments