Skip to content

Generation results in F821 Undefined name types error #1274

Description

@wirthual

Thank you for this great project!

Describe the bug
Ruff check of generated code is failing

Generating a client from an openapi.json file results in

Error(s) encountered while generating, client was not created

ruff failed

infinity_embedding_inference_server_client/models/embedding_object.py:34:58: F821 Undefined name `types`
Found 188 errors (187 fixed, 1 remaining).

OpenAPI Spec File
https://raw.githubusercontent.com/michaelfeil/infinity/main/docs/assets/openapi.json

Desktop (please complete the following information):

  • OS: Ubuntu 24.10
  • Python Version: Python 3.12.7
  • openapi-python-client version 0.25.1

Additional context
To reproduce:

 openapi-python-client generate            --url https://raw.githubusercontent.com/michaelfeil/infinity/main/docs/assets/openapi.json --overwrite
Generating /home/user/infinity/libs/client_infinity/infinity-embedding-inference-server-client

Error with ruff 0.4.10:

Error(s) encountered while generating, client was not created

ruff failed

infinity_embedding_inference_server_client/models/embedding_object.py:34:58: F821 Undefined name `types`
Found 188 errors (187 fixed, 1 remaining).

Error with ruff ruff-0.12.0

Error(s) encountered while generating, client was not created

ruff failed

infinity_embedding_inference_server_client/models/embedding_object.py:34:58: F821 Undefined name `types`
   |
33 |     def to_dict(self) -> dict[str, Any]:
34 |         embedding: Union[list[float], list[list[float]], types.FileTypes]
   |                                                          ^^^^^ F821
35 |         if isinstance(self.embedding, list):
36 |             embedding = self.embedding
   |

Found 280 errors (279 fixed, 1 remaining).

Fix:
Change

from ..types import UNSET, File, Unset
to
from ..types import UNSET, File, FileTypes, Unset

and 

    def to_dict(self) -> dict[str, Any]:
        embedding: Union[list[float], list[list[float]], types.FileTypes]
to
    def to_dict(self) -> dict[str, Any]:
        embedding: Union[list[float], list[list[float]], FileTypes]

Activity

  1. dbanty commented on Jul 3, 2025

    @dbanty
    Collaborator

    I don't think the document is accurate, because sending raw binary data within JSON isn't possible. So it might be that the document should have format: "byte" instead (base64-encoded)?

    But it's in a union, so maybe the API just only actually returns the integer arrays and not the binary data. Either way, the import error should be fixed with #1278

  2. added a commit that references this issue on Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions