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.
This commit is contained in:
Moritz Lell 2019-10-30 19:54:28 +01:00
commit 7f2d04d5ff

View file

@ -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)