Passer au contenu principal
Bluvy Tube
Appuyez sur Échap pour quitter le plein écran
Volume m
/
i
Mode Cinéma t
f
/
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.

Raccourcis clavier

Espace K
Lecture / pause
← →
Reculer / avancer de 5 s
J L
Reculer / avancer de 10 s
0–9
Aller à 0 %–90 % de la vidéo
Home End
Début / fin
, .
Image précédente / suivante (en pause)
< >
Ralentir / accélérer
↑ ↓
Volume
M
Couper / rétablir le son
C
Sous-titres
F
Plein écran
I
Image dans l’image
T
Mode cinéma
?
Afficher cette aide

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.

Bob Belderbos

Bob Belderbos

@bbelderbos.bsky.social

S'abonner
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.
1 commentaire
?
But wouldn’t it be better if the language made this kind of mistake harder to make in the first place?

In Rust 🦀, there are no default arguments, so this particular pitfall doesn't exist.
Its ownership rules also prevent multiple simultaneous mutable references to the same data, catching many potential bugs at compile time.

This is one example of how Rust makes you think differently about shared state.
Voir le post d'origine sur Bluesky
Lien copié dans le presse-papier

Connexion

Il est temps de faire une pause

Ça fait 30 minutes que vous enchaînez les vidéos : accordez-vous 5 minutes loin de l'écran. Levez-vous, étirez-vous, buvez un verre d'eau… Les vidéos vous attendront ici.