]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
♻ Refactor dict value extraction to minimize key lookups `fastapi/utils.py` (#3139)
authorShahriyar Rzayev <rzayev.shahriyar@yandex.com>
Thu, 12 May 2022 20:38:30 +0000 (00:38 +0400)
committerGitHub <noreply@github.com>
Thu, 12 May 2022 20:38:30 +0000 (20:38 +0000)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
fastapi/utils.py

index b9301499a27a70f612fc62bb6b6b9fd102b9cd36..9d720feb3758a25f0db0c849b3bca846c59c51af 100644 (file)
@@ -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(