Skip to content

fix: regenerate OpenAPI clients with TYPE_CHECKING imports for mypy#598

Merged
jhamon merged 1 commit into
ftsfrom
jhamon/sdk-270-fix-openapi-codegen-templates
Feb 2, 2026
Merged

fix: regenerate OpenAPI clients with TYPE_CHECKING imports for mypy#598
jhamon merged 1 commit into
ftsfrom
jhamon/sdk-270-fix-openapi-codegen-templates

Conversation

@jhamon

@jhamon jhamon commented Feb 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Regenerate all OpenAPI clients using updated Mustache templates that add TYPE_CHECKING blocks for static type analysis
  • This fixes mypy errors in generated code where model references were not recognized
  • The template submodule (codegen/python-oas-templates) has been updated to include proper TYPE_CHECKING imports

Problem

Generated OpenAPI code in pinecone/core/openapi/ had multiple mypy errors:

  1. Missing type imports (Dict, Any from typing)
  2. Undefined model references (SparseValues, ErrorResponseError, Document, etc.)
  3. Return type annotation issues

Solution

Updated the Mustache templates to add TYPE_CHECKING blocks that allow mypy to see type annotations while avoiding circular import issues at runtime:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from .model.some_model import SomeModel

def lazy_import():
    from .model.some_model import SomeModel
    globals()["SomeModel"] = SomeModel

Verification

uv run mypy pinecone/core/openapi  # No errors in generated code

Notes

There are pre-existing issues on the fts branch where SDK code imports non-existent models (e.g., ConfigureIndexRequestEmbed, IndexSpec). These imports reference models that don't exist in the current API spec and are not caused by this change - they are a separate issue that pre-dates this PR.

Related

Made with Cursor


Note

Low Risk
Low risk because changes are confined to generated OpenAPI client/model code and mainly add cast/TYPE_CHECKING imports for static typing; runtime behavior should be unchanged aside from type-hint surfaces.

Overview
Regenerates the OpenAPI Python clients/models to be more mypy-friendly by adding TYPE_CHECKING import blocks for referenced models and tightening return type annotations via typing.cast (including ApplyResult[...] unions for async_req).

Also removes a few # type: ignore markers on _composed_schemas helpers and updates the generated APIS_REPO_SHA in openapi_support/api_version.py.

Written by Cursor Bugbot for commit d699e3c. This will update automatically on new commits. Configure here.

@jhamon jhamon added the python Pull requests that update Python code label Feb 2, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Comment thread pinecone/core/openapi/db_data/model/hit.py Outdated
Regenerate all OpenAPI clients using updated Mustache templates that add
TYPE_CHECKING blocks for static type analysis. This fixes mypy errors in
generated code where model references were not recognized.

Changes:
- Template submodule updated to include TYPE_CHECKING imports
- All generated API and model files now pass mypy type checking
- Added proper type annotations for cross-referenced models

This unblocks SDK-116 (re-enable CI linting) by fixing the generated code.
Note: There are pre-existing issues on the fts branch where SDK code imports
non-existent models - these are separate from this template fix.

Closes SDK-270

Co-authored-by: Cursor <cursoragent@cursor.com>
@jhamon jhamon force-pushed the jhamon/sdk-270-fix-openapi-codegen-templates branch from 34f0d01 to d699e3c Compare February 2, 2026 18:13
@jhamon jhamon merged commit afc2f12 into fts Feb 2, 2026
7 checks passed
@jhamon jhamon deleted the jhamon/sdk-270-fix-openapi-codegen-templates branch February 2, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant