Ever had a Python 🐍 function silently reuse a list from a previous call? That’s the mutable default argument gotcha.
That list is created once, when the function is defined, and reused across calls.
The usual fix? Use None as the default and create the list inside the function.
Ever had a Python 🐍 function silently reuse a list from a previous call? That’s the mutable default argument gotcha. That list is created once, when the function is defined, and reused across calls. The usual fix? Use None as the default and create the list inside the function.
0 vue
Publié le 22/10/2026 08:22
0:21
Ever had a Python 🐍 function silently reuse a list from a previous call? That’s the mutable default argument gotcha.
That list is created once, when the function is defined, and reused across calls.
The usual fix? Use None as the default and create the list inside the function.
In Rust 🦀, there are no default arguments, so this particular pitfall doesn't exist.
This is one example of how Rust makes you think differently about shared state.