Skip to content

Commit

Permalink
Add list.remove() as instance of modification within loop
Browse files Browse the repository at this point in the history
Removing an item when looping causes the loop to skip over certain items.
  • Loading branch information
Sjord committed Nov 28, 2023
1 parent 54e7d73 commit f8c978a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/lang/correctness/list-modify-iterating.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@
for i in e:
print(i)
d.append(i)

# ruleid:list-modify-while-iterate
for i in e:
if i == 1:
e.remove(i)
4 changes: 4 additions & 0 deletions python/lang/correctness/list-modify-iterating.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ rules:
for $ELEMENT in $LIST:
...
$LIST.extend(...)
- pattern: |
for $ELEMENT in $LIST:
...
$LIST.remove(...)
metadata:
category: correctness
technology:
Expand Down

0 comments on commit f8c978a

Please sign in to comment.