Skip to content
Open
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
3 changes: 3 additions & 0 deletions random.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def add_item(item, items=[]):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Filename random.py shadows Python's standard library module.

Naming this file random.py will shadow the built-in random module. Any import random elsewhere in the project (or its dependencies) would import this file instead. Consider renaming to something more descriptive.

🧰 Tools
🪛 Ruff (0.15.2)

[warning] 1-1: Do not use mutable data structures for argument defaults

Replace with None; initialize within function

(B006)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@random.py` at line 1, The file name random.py shadows Python's stdlib random
module; rename the file (e.g., items_helper.py or collection_utils.py) and
update any imports that reference this module to the new name, then run
tests/grep to ensure nothing else imports the old random.py; also keep the
function add_item(item, items=[]) but change its default mutable argument to
avoid shared-state bugs (e.g., accept items=None and set items=[] inside
add_item) and update any call sites accordingly.

items.append(item)
return items
Comment on lines +1 to +3
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Mutable default argument causes shared state across calls.

Using items=[] as a default creates a single list object at function definition time that is reused across all calls. Successive calls without an explicit items argument will accumulate results:

add_item("a")  # returns ["a"]
add_item("b")  # returns ["a", "b"] — not ["b"]

This is flagged by Ruff B006. The standard fix is to default to None and create a new list inside the function body.

🐛 Proposed fix
-def add_item(item, items=[]):
+def add_item(item, items=None):
+    if items is None:
+        items = []
     items.append(item)
     return items
🧰 Tools
🪛 Ruff (0.15.2)

[warning] 1-1: Do not use mutable data structures for argument defaults

Replace with None; initialize within function

(B006)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@random.py` around lines 1 - 3, The function add_item uses a mutable default
argument items=[], causing shared state across calls; change the signature to
default items to None and inside add_item check if items is None then assign
items = [] before appending, ensuring each call without an explicit items
receives a fresh list (update the parameter and the initialization logic in
add_item).