openapi-python-client icon indicating copy to clipboard operation
openapi-python-client copied to clipboard

Generation results in F821 Undefined name `types` error

Open wirthual opened this issue 4 months ago • 0 comments

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]


wirthual avatar Jun 21 '25 02:06 wirthual