Skip to content

Commit

Permalink
Do not update dictionary in-place in loop
Browse files Browse the repository at this point in the history
Trying to update the dictionary in-place in the loop leads to an error
in python 3.8 ("dictionary keys changed during iteration"). Instead,
create a copy of the dictionary, modified as needed.

Resolves ESMCI/manage_externals#135
  • Loading branch information
billsacks committed Mar 2, 2020
1 parent 7e8474b commit 37e4c4a
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions manic/sourcetree.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,20 @@ def status(self, relative_path_base=LOCAL_PATH_INDICATOR):
for comp in load_comps:
printlog('{0}, '.format(comp), end='')
stat = self._all_components[comp].status()
stat_final = {}
for name in stat.keys():
# check if we need to append the relative_path_base to
# the path so it will be sorted in the correct order.
if not stat[name].path.startswith(relative_path_base):
stat[name].path = os.path.join(relative_path_base,
stat[name].path)
# store under key = updated path, and delete the
# old key.
comp_stat = stat[name]
del stat[name]
stat[comp_stat.path] = comp_stat
summary.update(stat)
if stat[name].path.startswith(relative_path_base):
# use as is, without any changes to path
stat_final[name] = stat[name]
else:
# append relative_path_base to path and store under key = updated path
modified_path = os.path.join(relative_path_base,
stat[name].path)
stat_final[modified_path] = stat[name]
stat_final[modified_path].path = modified_path
summary.update(stat_final)

return summary

Expand Down

0 comments on commit 37e4c4a

Please sign in to comment.