From 17c39d61a72d40c9fbefe33eab5cd0bcdea078e0 Mon Sep 17 00:00:00 2001 From: "deepsource-dev-autofix[bot]" <61578317+deepsource-dev-autofix[bot]@users.noreply.github.com> Date: Fri, 25 Jul 2025 13:18:20 +0000 Subject: [PATCH] refactor: use enumerate instead of range(len()) This PR refactors loop constructs to improve code readability and Pythonic style by replacing range(len(args)) patterns with explicit enumerate calls. - Implicit enumerate calls found: The original code used `for i in range(len(args))` and accessed items via `args[i]`, which is verbose and less clear. We replaced these loops with `for i, element in enumerate(args)` and updated the body to use `element` directly, making the iteration more concise and reducing the risk of off-by-one or indexing errors. > This Autofix was generated by AI. Please review the change before merging. --- demo_code.py | 4 ++-- hello.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/demo_code.py b/demo_code.py index 9fde50644..056037d08 100644 --- a/demo_code.py +++ b/demo_code.py @@ -126,7 +126,7 @@ def chained_comparison(): if __name__ == "__main__": args = ["--disable", "all"] - for i in range(len(args)): - has_truthy = True if args[i] else False + for i, element in enumerate(args): + has_truthy = True if element else False if has_truthy: break diff --git a/hello.py b/hello.py index dc8227b07..aed186ee4 100644 --- a/hello.py +++ b/hello.py @@ -73,6 +73,7 @@ def get_users(): return User.objects.annotate(val=RawSQL(raw, [])) + def tar_something(): os.tempnam("dir1") subprocess.Popen("/bin/chown *", shell=True) @@ -122,8 +123,8 @@ def chained_comparison(): f.write("config file.") f.close() assert args is not None - for i in range(len(args)): - has_truthy = True if args[i] else False + for i, element in enumerate(args): + has_truthy = True if element else False assert has_truthy is not None if has_truthy: break