From: Shahriyar Rzayev Date: Thu, 12 May 2022 20:38:30 +0000 (+0400) Subject: ♻ Refactor dict value extraction to minimize key lookups `fastapi/utils.py` (#3139) X-Git-Tag: 0.78.0~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=82775f7cd01f93ca10ed7dcf0081d5c746e62068;p=thirdparty%2Ffastapi%2Ffastapi.git ♻ Refactor dict value extraction to minimize key lookups `fastapi/utils.py` (#3139) Co-authored-by: Sebastián Ramírez --- diff --git a/fastapi/utils.py b/fastapi/utils.py index b9301499a2..9d720feb37 100644 --- a/fastapi/utils.py +++ b/fastapi/utils.py @@ -147,15 +147,15 @@ def generate_unique_id(route: "APIRoute") -> str: def deep_dict_update(main_dict: Dict[Any, Any], update_dict: Dict[Any, Any]) -> None: - for key in update_dict: + for key, value in update_dict.items(): if ( key in main_dict and isinstance(main_dict[key], dict) - and isinstance(update_dict[key], dict) + and isinstance(value, dict) ): - deep_dict_update(main_dict[key], update_dict[key]) + deep_dict_update(main_dict[key], value) else: - main_dict[key] = update_dict[key] + main_dict[key] = value def get_value_or_default(