8000 ♻ Refactor dict value extraction to minimize key lookups `fastapi/utils.py` by ShahriyarR · Pull Request #3139 · fastapi/fastapi · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
unpack the value using .items() to eliminate 3 extra key lookup
  • Loading branch information
ShahriyarR committed Apr 29, 2021
commit 32df705c70d2835e74c2da9ea4471a8b176517f0
8 changes: 4 additions & 4 deletions fastapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ def generate_operation_id_for_path(*, name: str, path: str, method: str) -> 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(
Expand Down
0