-
Notifications
You must be signed in to change notification settings - Fork 1
Add function to append item to list #1
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| def add_item(item, items=[]): | ||
| items.append(item) | ||
| return items | ||
|
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mutable default argument causes shared state across calls. Using 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 🐛 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 (B006) 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filename
random.pyshadows Python's standard library module.Naming this file
random.pywill shadow the built-inrandommodule. Anyimport randomelsewhere 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