Skip to content

Generation results in F821 Undefined name types error #1274

@wirthual

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions