I just type-annotated the entire codebase of openedx/code-annotations. The pull request is here: chore: add strict type annotations on the entire codebase by regisb · Pull Request #169 · openedx/code-annotations · GitHub
It’s taken me ~4h, during which I used Claude Code and spent $13.5 in API usage. Most of the time was spent adding some tooling on top of the repository (make
targets, requirements compilation, etc.) and reviewing changes made by Claude.
That last step was absolutely necessary, because (surprise surprise) AI models make mistakes. Still, generative AI allowed me to reach 100% coverage about 3-5x faster than if I had done it manually. After this last verification step, I feel pretty happy with the result.
I’m not going to share the exact Claude prompt I used, because it was very basic. It was something along those lines:
Annotate the code_annotations/ directory with types such that
mypy --strict
is successful. Don’t use typing.List/Dict/Tuple, but use the core list/dict/tuple classes instead.
And then rinse and repeat with the tests/
and test_utils/
subdirectories. Each time, I committed changes locally such that I could rollback the changes. Sometimes Claude was digging itself into a hole, especially with Sphinx annotations; in those cases, I had to intervene manually.
Some of the mistakes included things like:
result = some_function_that_can_return_none()
do_something_with(result)
that were changed to:
result = some_function_that_can_return_none()
if result is not None:
do_something_with(result)
which is very wrong.
I’m a big fan of type annotations in Python, and especially in Open edX. I really wish we could fully annotate the entire Python codebase, which would give us a lot more confidence in using the APIs, refactoring and testing changes. So this is a step forward that makes me super happy.
If the community feels good about this, and I find some free time, I’d like to apply the same technique to the other repositories that I maintain: edx-toggles (600 lines of code), django-config-models (1k LOC) and edx-django-utils (4.7k LOC).