File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -401,7 +401,7 @@ def change_dict_value(
401401 dotted_key : str ,
402402 change_value ,
403403 change_type = "value" ,
404- is_new : bool = False ,
404+ allow_new_key : bool = False ,
405405) -> dict :
406406 # change_value = func or value(any type)
407407 if "." in dotted_key :
@@ -418,19 +418,30 @@ def change_dict_value(
418418 sub_rest = rest .split ("." , 1 )[1 ]
419419 list_data .append (
420420 change_dict_value (
421- sub_data , sub_rest , change_value , change_type
421+ sub_data ,
422+ sub_rest ,
423+ change_value ,
424+ change_type ,
425+ allow_new_key = allow_new_key ,
422426 )
423427 )
424428 data [key ] = list_data
425429 elif isinstance (data [key ], dict ):
426430 data [key ] = change_dict_value (
427- data [key ], rest , change_value , change_type
431+ data [key ],
432+ rest ,
433+ change_value ,
434+ change_type ,
435+ allow_new_key = allow_new_key ,
428436 )
429437 else :
430- if dotted_key in data or is_new :
438+ if dotted_key in data :
431439 data [dotted_key ] = _change_value_by_type (
432440 change_type , data [dotted_key ], change_value
433441 )
442+ else :
443+ if allow_new_key :
444+ data [dotted_key ] = change_value
434445
435446 return data
436447
You can’t perform that action at this time.
0 commit comments