Exercise py-06 — timer, atomic_write and JSON repair for LLM output

Three small context-manager-and-parsing utilities, the exact shapes context managers and exceptions just walked. timer() and atomic_write(path) are context managers you'll write again for real: one measures a block without ever hiding what happened inside it, the other makes "half-written file on disk" impossible by construction. repair_json is the function every structured-output LLM feature needs on day one — models emit JSON wrapped in prose, fenced in markdown, with a trailing comma or a truncated tail when the response got cut off, and your pipeline has to salvage it or reject it cleanly, never guess.

~75 minruns in the browser 8 checkspy-06

What you're building

The checks are ordinary Python and ship with the page like everything else on a static site — you could read them in devtools if you wanted. One of them writes a real temporary file and injects a real exception mid-write to prove atomic_write's guarantee; that filesystem access works the same way in Pyodide's in-memory filesystem as it does here.

If you get stuck