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:
parent
efab08fc9f
commit
7f2d04d5ff
1 changed files with 5 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue