From 7f2d04d5fffdbe7632f78898aa3f8346bb162bea Mon Sep 17 00:00:00 2001 From: Moritz Lell Date: Wed, 30 Oct 2019 19:54:28 +0100 Subject: [PATCH] Prevent iterator being changed while iterating In Python 3, `zip()` returns an iterator that in turn contains references to `tparts` and `bparts`. Because those two variables are modified within the loop, the iterator does not advance properly. Fix this by explicitly obtaining a list. --- redo/state.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/redo/state.py b/redo/state.py index 667a3d8..19458ee 100644 --- a/redo/state.py +++ b/redo/state.py @@ -184,7 +184,11 @@ def relpath(t, base): base = os.path.normpath(_realdirpath(base)) tparts = t.split('/') bparts = base.split('/') - for tp, bp in zip(tparts, bparts): + + # zip must not return an iterator in python 3, because the source lists of + # the iterators are changed. The iterator does not notice that and ends too + # soon. + for tp, bp in list(zip(tparts, bparts)): if tp != bp: break tparts.pop(0)