Add type annotations
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.9k
- Forks
- 323
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 12
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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the CodeCarbon source files and confirm maintainer direction on inline PEP 484/561 annotations versus a separate stub package. Use stubgen to inspect an initial typing skeleton, then determine the core public API scope, add codecarbon/py.typed, and verify the annotations with mypy or pyright in CI.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100