@@ -295,25 +295,41 @@ def _cast_instance_to_schema(
295295 p_type = p_schema .get ("type" )
296296 if p_type == "object" and isinstance (val , dict ):
297297 nested_schema = GtsEntityCastResult ._effective_object_schema (p_schema )
298- new_obj , add_sub , rem_sub , new_incompatibility_reasons = GtsEntityCastResult ._cast_instance_to_schema (
299- val , nested_schema , base_path = (f"{ base_path } .{ prop } " if base_path else prop ), incompatibility_reasons = incompatibility_reasons
298+ new_obj , add_sub , rem_sub , new_incompatibility_reasons = (
299+ GtsEntityCastResult ._cast_instance_to_schema (
300+ val ,
301+ nested_schema ,
302+ base_path = (f"{ base_path } .{ prop } " if base_path else prop ),
303+ incompatibility_reasons = incompatibility_reasons ,
304+ )
300305 )
301306 result [prop ] = new_obj
302307 added .extend (add_sub )
303308 removed .extend (rem_sub )
304309 incompatibility_reasons .extend (new_incompatibility_reasons )
305310 elif p_type == "array" and isinstance (val , list ):
306311 items_schema = p_schema .get ("items" )
307- if isinstance (items_schema , dict ) and items_schema .get ("type" ) == "object" :
308- nested_schema = GtsEntityCastResult ._effective_object_schema (items_schema )
312+ if (
313+ isinstance (items_schema , dict )
314+ and items_schema .get ("type" ) == "object"
315+ ):
316+ nested_schema = GtsEntityCastResult ._effective_object_schema (
317+ items_schema
318+ )
309319 new_list : List [Any ] = []
310320 for idx , item in enumerate (val ):
311321 if isinstance (item , dict ):
312- new_item , add_sub , rem_sub , new_incompatibility_reasons = GtsEntityCastResult ._cast_instance_to_schema (
313- item ,
314- nested_schema ,
315- base_path = (f"{ base_path } .{ prop } [{ idx } ]" if base_path else f"{ prop } [{ idx } ]" ),
316- incompatibility_reasons = incompatibility_reasons ,
322+ new_item , add_sub , rem_sub , new_incompatibility_reasons = (
323+ GtsEntityCastResult ._cast_instance_to_schema (
324+ item ,
325+ nested_schema ,
326+ base_path = (
327+ f"{ base_path } .{ prop } [{ idx } ]"
328+ if base_path
329+ else f"{ prop } [{ idx } ]"
330+ ),
331+ incompatibility_reasons = incompatibility_reasons ,
332+ )
317333 )
318334 new_list .append (new_item )
319335 added .extend (add_sub )
@@ -481,23 +497,38 @@ def _check_constraint_compatibility(
481497 if prop_type in ("number" , "integer" ):
482498 errors .extend (
483499 GtsEntityCastResult ._check_min_max_constraint (
484- prop , old_prop_schema , new_prop_schema , "minimum" , "maximum" , check_tightening
500+ prop ,
501+ old_prop_schema ,
502+ new_prop_schema ,
503+ "minimum" ,
504+ "maximum" ,
505+ check_tightening ,
485506 )
486507 )
487508
488509 # String constraints
489510 if prop_type == "string" :
490511 errors .extend (
491512 GtsEntityCastResult ._check_min_max_constraint (
492- prop , old_prop_schema , new_prop_schema , "minLength" , "maxLength" , check_tightening
513+ prop ,
514+ old_prop_schema ,
515+ new_prop_schema ,
516+ "minLength" ,
517+ "maxLength" ,
518+ check_tightening ,
493519 )
494520 )
495521
496522 # Array constraints
497523 if prop_type == "array" :
498524 errors .extend (
499525 GtsEntityCastResult ._check_min_max_constraint (
500- prop , old_prop_schema , new_prop_schema , "minItems" , "maxItems" , check_tightening
526+ prop ,
527+ old_prop_schema ,
528+ new_prop_schema ,
529+ "minItems" ,
530+ "maxItems" ,
531+ check_tightening ,
501532 )
502533 )
503534
@@ -588,8 +619,10 @@ def _check_schema_compatibility(
588619
589620 # Recursively check nested object properties
590621 if old_type == "object" and new_type == "object" :
591- nested_compat , nested_errors = GtsEntityCastResult ._check_schema_compatibility (
592- old_prop_schema , new_prop_schema , check_backward
622+ nested_compat , nested_errors = (
623+ GtsEntityCastResult ._check_schema_compatibility (
624+ old_prop_schema , new_prop_schema , check_backward
625+ )
593626 )
594627 if not nested_compat :
595628 for err in nested_errors :
@@ -615,7 +648,9 @@ def _check_backward_compatibility(
615648 - Cannot add enum values
616649 - Cannot tighten constraints (decrease max, increase min, etc.)
617650 """
618- return GtsEntityCastResult ._check_schema_compatibility (old_schema , new_schema , check_backward = True )
651+ return GtsEntityCastResult ._check_schema_compatibility (
652+ old_schema , new_schema , check_backward = True
653+ )
619654
620655 @staticmethod
621656 def _check_forward_compatibility (
@@ -634,7 +669,9 @@ def _check_forward_compatibility(
634669 - Cannot remove enum values
635670 - Cannot relax constraints (increase max, decrease min, etc.)
636671 """
637- return GtsEntityCastResult ._check_schema_compatibility (old_schema , new_schema , check_backward = False )
672+ return GtsEntityCastResult ._check_schema_compatibility (
673+ old_schema , new_schema , check_backward = False
674+ )
638675
639676 @staticmethod
640677 def _diff_objects (
@@ -697,7 +734,9 @@ def _only_optional_add_remove(
697734 ) -> bool :
698735 if not isinstance (a , dict ) or not isinstance (b , dict ):
699736 if a != b :
700- reasons .append (f"{ GtsEntityCastResult ._path_label (path )} : value changed" )
737+ reasons .append (
738+ f"{ GtsEntityCastResult ._path_label (path )} : value changed"
739+ )
701740 return False
702741 return True
703742
0 commit comments