-
-
Notifications
You must be signed in to change notification settings - Fork 248
Description
CodeCarbon currently ships without type annotations and without a py.typed marker, which means static type checkers cannot provide type checking, autocompletion, or inline documentation for CodeCarbon code. Adding type support would be a meaningful quality-of-life improvement.
What I'm proposing
I'd like to contribute inline type annotations directly to CodeCarbon's source files, following PEP 484 and PEP 561. Concretely, this would involve:
- Annotating function signatures and class attributes across CodeCarbon's public API, starting with the most commonly used surfaces.
- Adding an empty
codecarbon/py.typedmarker file, which signals to type checkers that the package supports typing. - Ensuring the annotations are verified by running mypy and/or pyright in CI, so they don't silently drift out of sync with the implementation.
I plan to use stubgen (from mypy) to generate an initial skeleton, then refine the signatures by hand, particularly for the more complex parts of the API that involve union types or overloads.
A separate types-codecarbon package on PyPI is an alternative, but inline annotations are generally the preferred long-term solution because the types live alongside the code and stay in sync naturally with each release. A separate package creates a maintenance burden where type stubs can lag behind the library's actual API.
Before I start
I wanted to open this issue first to check a few things:
- Are the maintainers open to this change in principle?
- Is there a preference for inline annotations vs. a separate stub package?
- Are there any parts of the codebase that might need special treatment?
Happy to start with a focused PR covering just the core public API and expand from there based on feedback. Please do let me know your thoughts!