blas1n/claude-skills/python-mutation-traps
Claude Code and agent skill by blas1n/claude-skills
- community
Checking that the SKILL.md file is still in the repository.
Python data mutation traps — mutable defaults, dict reference detach, async concurrent modification
Install
npx vskill@latest install blas1n/claude-skills/python-mutation-trapsSKILL.md
The same SKILL.md was published earlier as blas1n/claude-skills/python-mutation-traps.
Python Data Mutation Traps
1. Mutable Defaults (Shallow Copy Trap)
dict(), list(), .copy(), {**d} only perform shallow copies. Nested mutable objects remain shared references.
Fix: Always use copy.deepcopy() for nested mutable structures.
Detection: Module-level dict/list with nested mutables + copied with dict()/.copy() + nested values mutated after copying.
2. Dict Reference Detach Trap
List comprehension filtering creates a new list, not a view. If you pop the dict key then append to the filtered list, the append is a no-op on the dict.
Fix: Always reassign back before appending, or mutate in-place with slice assignment:
3. Async Concurrent Modification
In async code, iterating a mutable list in one coroutine while another modifies it causes ValueError or silent data loss.
Fix: Snapshot iteration with list[:]:
Checklist:
- [ ] Are there async functions that iterate and modify the same collection?
- [ ] Can two coroutines run concurrently on the same data?
- [ ] Is iteration over
list[:](snapshot)? - [ ] Is removal inside
contextlib.suppress(ValueError)?
Related
- YAML
safe_loadauto-parses dates → compare withstr(value) - Sync→async refactor: change
MagicMocktoAsyncMockfor awaited methods
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/python-mutation-traps/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/blas1n/claude-skills/python-mutation-traps)