@@ -853,6 +853,38 @@ def _structure_dict(self, obj: Mapping[T, V], cl: Any) -> dict[T, V]:
853853 if is_bare (cl ) or cl .__args__ == (Any , Any ):
854854 return dict (obj )
855855 key_type , val_type = cl .__args__
856+
857+ if self .detailed_validation :
858+ key_handler = self ._structure_func .dispatch (key_type )
859+ val_handler = self ._structure_func .dispatch (val_type )
860+ errors = []
861+ res = {}
862+
863+ for k , v in obj .items ():
864+ try :
865+ value = val_handler (v , val_type )
866+ except Exception as exc :
867+ msg = IterableValidationNote (
868+ f"Structuring mapping value @ key { k !r} " , k , val_type
869+ )
870+ exc .__notes__ = [* getattr (exc , "__notes__" , []), msg ]
871+ errors .append (exc )
872+ continue
873+
874+ try :
875+ key = key_handler (k , key_type )
876+ res [key ] = value
877+ except Exception as exc :
878+ msg = IterableValidationNote (
879+ f"Structuring mapping key @ key { k !r} " , k , key_type
880+ )
881+ exc .__notes__ = [* getattr (exc , "__notes__" , []), msg ]
882+ errors .append (exc )
883+
884+ if errors :
885+ raise IterableValidationError (f"While structuring { cl !r} " , errors , cl )
886+ return res
887+
856888 if key_type in ANIES :
857889 val_conv = self ._structure_func .dispatch (val_type )
858890 return {k : val_conv (v , val_type ) for k , v in obj .items ()}
0 commit comments