@@ -155,7 +155,7 @@ def _validate_out_of_order_table(self, key: SingleKey | None = None) -> None:
155155 return
156156 if key not in self ._map or not isinstance (self ._map [key ], tuple ):
157157 return
158- OutOfOrderTableProxy (self , self ._map [key ])
158+ OutOfOrderTableProxy . validate (self , self ._map [key ])
159159
160160 def append (
161161 self , key : Key | str | None , item : Item , validate : bool = True
@@ -786,7 +786,21 @@ def _previous_item(self, idx: int | None = None, ignore=(Null,)) -> Item | None:
786786
787787
788788class OutOfOrderTableProxy (_CustomDict ):
789- def __init__ (self , container : Container , indices : tuple [int ]) -> None :
789+ @staticmethod
790+ def validate (container : Container , indices : tuple [int , ...]) -> None :
791+ """Validate out of order tables in the given container"""
792+ # Append all items to a temp container to see if there is any error
793+ temp_container = Container (True )
794+ for i in indices :
795+ _ , item = container ._body [i ]
796+
797+ if isinstance (item , Table ):
798+ for k , v in item .value .body :
799+ temp_container .append (k , v , validate = False )
800+
801+ temp_container ._validate_out_of_order_table ()
802+
803+ def __init__ (self , container : Container , indices : tuple [int , ...]) -> None :
790804 self ._container = container
791805 self ._internal_container = Container (True )
792806 self ._tables = []
@@ -799,7 +813,7 @@ def __init__(self, container: Container, indices: tuple[int]) -> None:
799813 self ._tables .append (item )
800814 table_idx = len (self ._tables ) - 1
801815 for k , v in item .value .body :
802- self ._internal_container .append (k , v , validate = False )
816+ self ._internal_container ._raw_append (k , v )
803817 self ._tables_map [k ] = table_idx
804818 if k is not None :
805819 dict .__setitem__ (self , k .key , v )
0 commit comments