1---2name: python3description: Write reliable Python avoiding mutable defaults, import traps, and common runtime surprises.4---56## Quick Reference78| Topic | File |9|-------|------|10| Dynamic typing, type hints, duck typing | `types.md` |11| List/dict/set gotchas, comprehensions | `collections.md` |12| Args/kwargs, closures, decorators, generators | `functions.md` |13| Inheritance, descriptors, metaclasses | `classes.md` |14| GIL, threading, asyncio, multiprocessing | `concurrency.md` |15| Circular imports, packages, __init__.py | `imports.md` |16| Pytest, mocking, fixtures | `testing.md` |1718## Critical Rules1920- `def f(items=[])` shares list across all calls — use `items=None` then `items = items or []`21- `is` checks identity, `==` checks equality — `"a" * 100 is "a" * 100` may be False22- Modifying list while iterating skips elements — iterate over copy: `for x in list(items):`23- GIL prevents true parallel Python threads — use multiprocessing for CPU-bound24- Bare `except:` catches `SystemExit` and `KeyboardInterrupt` — use `except Exception:`25- `UnboundLocalError` when assigning to outer scope variable — use `nonlocal` or `global`26- `open()` without context manager leaks handles — always use `with open():`27- Circular imports fail silently or partially — import inside function to break cycle28- `0.1 + 0.2 != 0.3` — floating point, use `decimal.Decimal` for money29- Generator exhausted after one iteration — can't reuse, recreate or use `itertools.tee`30- Class attributes with mutables shared across instances — define in `__init__` instead31- `__init__` is not constructor — `__new__` creates instance, `__init__` initializes32- Default encoding is platform-dependent — always specify `encoding='utf-8'`