Skip to content

Commit 37e4c4a

Browse files
committed
Do not update dictionary in-place in loop
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 #135
1 parent 7e8474b commit 37e4c4a

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

manic/sourcetree.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,20 @@ def status(self, relative_path_base=LOCAL_PATH_INDICATOR):
299299
for comp in load_comps:
300300
printlog('{0}, '.format(comp), end='')
301301
stat = self._all_components[comp].status()
302+
stat_final = {}
302303
for name in stat.keys():
303304
# check if we need to append the relative_path_base to
304305
# the path so it will be sorted in the correct order.
305-
if not stat[name].path.startswith(relative_path_base):
306-
stat[name].path = os.path.join(relative_path_base,
307-
stat[name].path)
308-
# store under key = updated path, and delete the
309-
# old key.
310-
comp_stat = stat[name]
311-
del stat[name]
312-
stat[comp_stat.path] = comp_stat
313-
summary.update(stat)
306+
if stat[name].path.startswith(relative_path_base):
307+
# use as is, without any changes to path
308+
stat_final[name] = stat[name]
309+
else:
310+
# append relative_path_base to path and store under key = updated path
311+
modified_path = os.path.join(relative_path_base,
312+
stat[name].path)
313+
stat_final[modified_path] = stat[name]
314+
stat_final[modified_path].path = modified_path
315+
summary.update(stat_final)
314316

315317
return summary
316318

0 commit comments

Comments
 (0)