mlco2 / mlco2/codecarbon

Add type annotations

Open
#1,090 7 comments 0 reactions 0 assignees View on GitHub

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.typed marker 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:

  1. Are the maintainers open to this change in principle?
  2. Is there a preference for inline annotations vs. a separate stub package?
  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.