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(
401
401
dotted_key : str ,
402
402
change_value ,
403
403
change_type = "value" ,
404
- is_new : bool = False ,
404
+ allow_new_key : bool = False ,
405
405
) -> dict :
406
406
# change_value = func or value(any type)
407
407
if "." in dotted_key :
@@ -418,19 +418,30 @@ def change_dict_value(
418
418
sub_rest = rest .split ("." , 1 )[1 ]
419
419
list_data .append (
420
420
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 ,
422
426
)
423
427
)
424
428
data [key ] = list_data
425
429
elif isinstance (data [key ], dict ):
426
430
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 ,
428
436
)
429
437
else :
430
- if dotted_key in data or is_new :
438
+ if dotted_key in data :
431
439
data [dotted_key ] = _change_value_by_type (
432
440
change_type , data [dotted_key ], change_value
433
441
)
442
+ else :
443
+ if allow_new_key :
444
+ data [dotted_key ] = change_value
434
445
435
446
return data
436
447
You can’t perform that action at this time.
0 commit comments