-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from AghilesAzzoug/404-PYT
feat: add tests for rule PYT404
- Loading branch information
Showing
1 changed file
with
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
def non_compliant_example_basic(): | ||
for var in [var2 for var2 in range(1000)]: # Noncompliant {{Use generator comprehension instead of list comprehension in for loop declaration}} | ||
print(var) | ||
|
||
def non_compliant_example_enumerate(): | ||
for idx, var in enumerate([var2 for var2 in range(1000)]): # Noncompliant {{Use generator comprehension instead of list comprehension in for loop declaration}} | ||
print(var) | ||
|
||
def non_compliant_example_zip(): | ||
for var, var_ in zip([var2 for var2 in range(1000)], [var2 for var2 in range(1000)]): # Noncompliant {{Use generator comprehension instead of list comprehension in for loop declaration}} {{Use generator comprehension instead of list comprehension in for loop declaration}} | ||
print(var) | ||
|
||
def compliant_example_basic_1(): | ||
for var in range(10): | ||
print(var) | ||
|
||
def compliant_example_basic_2(): | ||
for var in (var2 for var2 in range(1000)): | ||
print(var) | ||
|
||
def compliant_example_with_filter(): | ||
for var in filter(lambda x: x > 2, range(100)): | ||
print(var) | ||
|
||
def compliant_example_with_enumerate(): | ||
for idx, var in enumerate(range(1000)): | ||
print(var) | ||
|
||
def compliant_example_with_zip(): | ||
for var, var2 in zip((idx for idx in range(3)), ["a", "b", "c"]): | ||
print(var) |