Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tests for rule PYT404 #1

Merged
merged 3 commits into from
May 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/AvoidListComprehensionInIterations.py
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)