mutation — why your code mysteriously breaks6 / 9
shallow copy, deep copy, and the nested-dict bug
Claude wrote a "make a backup before editing" snippet. The bug: it used
.copy() on a nested dict. When the script edits the backup's nested
tags list, the original list also changes.
The expected output is:
original tags: ['admin']
backup tags: ['admin', 'temp']
Right now it's:
original tags: ['admin', 'temp']
backup tags: ['admin', 'temp']
Fix line 5 so the backup is truly independent. The copy module is already
imported on line 1.
The break is on line 5 — but read the whole snippet first.
⌘↵ runs the editor.
Booting Python…
Output
[promptdojo:~]$ _