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

Remove mutable default args #2482

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

elayeek
Copy link

@elayeek elayeek commented Aug 13, 2024

This is a common pitfall in Python that causes unexpected behavior.

Python evaluates functions on module load and generates mutable default argument objects once, then persist them whenever the function is called.

Fixes #2483

@elayeek elayeek force-pushed the remove_default_mutable_antipattern branch from b40c109 to b98d53b Compare August 13, 2024 16:56
This is a common pitfall in Python that causes unexpected behavior.
Python evaluates functions on module load and generates mutable default argument objects once, then persist them whenever the function is called.
@elayeek elayeek force-pushed the remove_default_mutable_antipattern branch from b98d53b to 4109bb4 Compare August 13, 2024 17:02
@elayeek elayeek changed the title Removing mutable default args Remove mutable default args Aug 13, 2024
Copy link
Member

@tienne-B tienne-B left a comment

Choose a reason for hiding this comment

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

I'll wait for a linting commit (and for the CI to run after that) to merge this in.

Comment on lines +16 to +19
# IDE files
.idea/
.vscode/

Copy link
Member

Choose a reason for hiding this comment

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

I think these could more efficiently be in your global gitignore, rather than being project-specific.

Copy link
Author

Choose a reason for hiding this comment

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

True, will fix that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Potential Bug: Use of mutable default arguments in python
2 participants