Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deepupdate change recursion to loop #625

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
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
20 changes: 12 additions & 8 deletions src/apispec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,19 @@ def dedent(content):
return content.strip()


# http://stackoverflow.com/a/8310229
# http://stackoverflow.com/a/8310229 #+ recursion -> loop
def deepupdate(original, update):
"""Recursively update a dict.
"""Iteratively update a dict.

Subdict's won't be overwritten but also updated.
"""
for key, value in original.items():
if key not in update:
update[key] = value
elif isinstance(value, dict):
deepupdate(value, update[key])
return update
result = update
stack = [(original, update)]
while stack:
original, update = stack.pop()
for key, value in original.items():
if key not in update:
update[key] = value
elif isinstance(value, dict):
stack.append((value, update[key]))
return result