-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rules): Add rule to check for mutations of loop iterator
- Loading branch information
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
""" | ||
Should emit: | ||
B999 - on lines 11, 25, 26, 40, 46 | ||
""" | ||
|
||
|
||
some_list = [1, 2, 3] | ||
for elem in some_list: | ||
print(elem) | ||
if elem % 2 == 0: | ||
some_list.remove(elem) # should error | ||
|
||
some_list = [1, 2, 3] | ||
some_other_list = [1, 2, 3] | ||
for elem in some_list: | ||
print(elem) | ||
if elem % 2 == 0: | ||
some_other_list.remove(elem) # should not error | ||
|
||
|
||
some_list = [1, 2, 3] | ||
for elem in some_list: | ||
print(elem) | ||
if elem % 2 == 0: | ||
del some_list[2] # should error | ||
del some_list | ||
|
||
|
||
class A: | ||
some_list: list | ||
|
||
def __init__(self, ls): | ||
self.some_list = list(ls) | ||
|
||
|
||
a = A((1, 2, 3)) | ||
for elem in a.some_list: | ||
print(elem) | ||
if elem % 2 == 0: | ||
a.some_list.remove(elem) # should error | ||
|
||
a = A((1, 2, 3)) | ||
for elem in a.some_list: | ||
print(elem) | ||
if elem % 2 == 0: | ||
del a.some_list[2] # should error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters