python-developmentlisted
Install: claude install-skill ProjAnvil/MindForge
# Python Development — Language Core
This skill is about the Python language itself: its syntax, type system, concurrency and async model, the GIL, generators, context managers, and the idioms and gotchas that follow from the data model. It is deliberately framework-neutral. App-level and framework recipes live in `references/`; see the Framework Selection section below.
## Gotchas
Each trap is written as symptom → why → fix, because the *why* is the part worth remembering.
### 1. Mutable default arguments
- Symptom: a function "remembers" data across calls; `def add(x, bucket=[])` keeps growing.
- Why: default values are evaluated once, when the `def` executes, and that one object is reused.
- Fix: default to `None` and build the object inside the body.
```python
def add(x, bucket=None):
if bucket is None: # a fresh object on every call
bucket = []
bucket.append(x)
return bucket
```
### 2. Late-binding closures in loops
- Symptom: a list of lambdas all return the last loop value.
- Why: closures capture the *variable*, not its value, and resolve it when called — after the loop ends.
- Fix: freeze the value now with a default argument.
```python
funcs = [lambda i=i: i for i in range(3)] # bind i at definition time
```
### 3. GIL and CPU-bound work
- Symptom: adding threads does not speed up a CPU-heavy loop; it can even be slower.
- Why: the GIL lets one thread execute bytecode at a time, so CPU-bound threads serialize.
- Fix: use process