-
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 (#446)
* feat(rules): Add rule to check for mutations of loop iterator * fixup! feat(rules): Add rule to check for mutations of loop iterator * doc(B038): Add doc for B038 to README.rst --------- Co-authored-by: Cooper Lees <me@cooperlees.com>
- Loading branch information
1 parent
6c96f75
commit 7c823af
Showing
4 changed files
with
129 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
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