pylint: Fix modified-iterating-list

https://pylint.pycqa.org/en/latest/user_guide/messages/warning/modified-iterating-list.html:
> Emitted when items are added or removed to a list being iterated
through. Doing so can result in unexpected behaviour, that is why it is
preferred to use a copy of the list.

https://docs.python.org/3/tutorial/controlflow.html#for-statements:
> Code that modifies a collection while iterating over that same
collection can be tricky to get right. Instead, it is usually more
straight-forward to loop over a copy of the collection or to create a
new collection

Fixes: https://pagure.io/freeipa/issue/9278
Signed-off-by: Stanislav Levin <slev@altlinux.org>
Reviewed-By: Stanislav Levin <slev@altlinux.org>
This commit is contained in:
Stanislav Levin authored and Florence Blanc-Renaud committed 2023-01-10 08:30:58 +01:00
1 parent 0e03315299
commit 24db4dc876
2 files changed
+12 -6

No files matched your search

+5 -2
View File
@@ -1350,7 +1350,9 @@ def two_connected_topo(master, replicas):
yield v1, v3
grow.append((v1, v3))
for (r, s) in grow:
i = 0
while i < len(grow):
r, s = grow[i]
t = pool.pop(0)
for (u, v) in [(r, t), (s, t)]:
@@ -1360,7 +1362,8 @@ def two_connected_topo(master, replicas):
x = pool.pop(0)
yield v, x
yield w, x
grow.append((w, x)) # pylint: disable=modified-iterating-list
grow.append((w, x))
i += 1
except IndexError:
return