Type-Safe Python Decorators
Decorators are everywhere in Python. Logging, retries, caching, auth checks - if you’ve built anything non-trivial, you’ve written one. But the moment you try to add type hints, things get weird. Your IDE loses autocomplete. You end up with Callable[..., Any] and pretend the problem doesn’t exist, because Callable can’t express “whatever arguments the wrapped function takes.” PEP 612 introduced ParamSpec (Python 3.10+) to solve exactly this. This post walks through using it - from trivial cases to the genuinely painful scenarios I hit while building a multi-LLM agent backend. Read the TL;DR section for a quick summary. ...