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

Python Mutable Defaults Are The Source of All Evil - Florimond Manca #424

Open
utterances-bot opened this issue Mar 3, 2023 · 4 comments
Labels
comments Comments from utterances

Comments

@utterances-bot
Copy link

Python Mutable Defaults Are The Source of All Evil - Florimond Manca

How to prevent a common Python mistake that can lead to horrible bugs and waste everyone's time.

https://florimond.dev/en/posts/2018/08/python-mutable-defaults-are-the-source-of-all-evil/

Copy link

JC-swEng commented Mar 3, 2023

Thank you very much for this lesson!!

Copy link

rfichi commented Jul 6, 2023

Hey man thanks for this post, I always set None for default arguments because is a good practice, but never actually understood why? Now I know what can happen if a use mutable arguments as default!

Copy link

Python default arguments are evaluated only once, when the function is defined, not when its called. So if the default argument is a mutable and is mutated inside the function, it wil stay mutated when you call the function again.

@florimondmanca florimondmanca added the comments Comments from utterances label Dec 14, 2023
Copy link

You saved my day!

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

No branches or pull requests

6 participants