Skip to content

fix: add missing type annotations to public API functions#619

Merged
planetf1 merged 1 commit into
generative-computing:mainfrom
planetf1:mellea-e
Mar 13, 2026
Merged

fix: add missing type annotations to public API functions#619
planetf1 merged 1 commit into
generative-computing:mainfrom
planetf1:mellea-e

Conversation

@planetf1

@planetf1 planetf1 commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Misc PR

Type of PR

  • Bug Fix
  • New Feature
  • Documentation
  • Other

Description

Adds missing return-type and parameter annotations to ~75 functions across 14 public API files. Griffe (the doc pipeline) requires annotations to generate correct return-type cross-references in the API reference; without them it emits no_returns audit failures and renders stubs with no linked types. Two latent bugs were also surfaced: _md_list/_md_table were returning bare bool where Requirement.validation_fn expects ValidationResult, and to_validationresult_reason had a narrowing gap that mypy could not verify. Both are fixed here.

Testing

  • Tests added to the respective file if code was changed
  • New code has 100% coverage if code as added
  • Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)

@mergify

mergify Bot commented Mar 11, 2026

Copy link
Copy Markdown

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert|release)(?:\(.+\))?:

@github-actions

Copy link
Copy Markdown
Contributor

The PR description has been updated. Please fill out the template for your PR to be reviewed.

@planetf1
planetf1 marked this pull request as ready for review March 11, 2026 14:35
@planetf1
planetf1 requested review from a team and nrfulton as code owners March 11, 2026 14:35
@planetf1 planetf1 added the documentation Improvements or additions to documentation label Mar 11, 2026

@jakelorocco jakelorocco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes seem reasonable. Were these changes made through Bob or a formal type system? Would like to know to help confirm whether we need to check all by hand.

@planetf1

Copy link
Copy Markdown
Contributor Author

@psschwei

Reviewed all Any annotations introduced in this PR. Most are correct and necessary — e.g. the OpenTelemetry span types in tracing.py, where the dependency is optional and safely naming those types at runtime would require both TYPE_CHECKING and try/except guards for no real gain.

One avoidable Any fixed: model: Anymodel: PreTrainedModel in tokens_to_legacy_cache (kv_block_helpers.py) — transformers is already an unconditional import there. The LegacyCache = Any alias in the same file is intentional (no stable public type for the legacy cache tuple format).

Adds return type and parameter annotations to ~50 functions across the
14 high-priority public API files identified in issue generative-computing#615.

Also fixes two latent type bugs uncovered during annotation:
- stdlib/requirements/md.py: _md_list/_md_table were returning bare bool
  where Requirement.validate() expected ValidationResult; wrap in
  ValidationResult(result=...)
- stdlib/tools/interpreter.py: add narrowing asserts for stdout/stderr
  to confirm the -> str return type that the top-level assert guarantees

Closes generative-computing#615
@planetf1

planetf1 commented Mar 12, 2026

Copy link
Copy Markdown
Contributor Author

These changes seem reasonable. Were these changes made through Bob or a formal type system? Would like to know to help confirm whether we need to check all by hand.

by claude - note one correction above from a lazy Any. That has been left on tracing due to import complexities (which would need multiple guards and add little benefit).

This is a subset of missing mypy annotations - selection was driven by references in the newly generated api docs (to be merged)

@planetf1
planetf1 requested a review from jakelorocco March 12, 2026 10:15
@planetf1
planetf1 enabled auto-merge March 12, 2026 12:23

@jakelorocco jakelorocco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes seem reasonable

@planetf1
planetf1 added this pull request to the merge queue Mar 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 12, 2026
@planetf1
planetf1 added this pull request to the merge queue Mar 13, 2026
Merged via the queue into generative-computing:main with commit 97b2ceb Mar 13, 2026
4 checks passed
akihikokuroda pushed a commit to akihikokuroda/mellea that referenced this pull request May 27, 2026
…-computing#619)

Adds return type and parameter annotations to ~50 functions across the
14 high-priority public API files identified in issue generative-computing#615.

Also fixes two latent type bugs uncovered during annotation:
- stdlib/requirements/md.py: _md_list/_md_table were returning bare bool
  where Requirement.validate() expected ValidationResult; wrap in
  ValidationResult(result=...)
- stdlib/tools/interpreter.py: add narrowing asserts for stdout/stderr
  to confirm the -> str return type that the top-level assert guarantees

Closes generative-computing#615
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: add missing type annotations to public API functions

2 participants