-
-
Notifications
You must be signed in to change notification settings - Fork 259
Description
Describe the bug
Running with --meta none prints a bunch of F811 errors from ruff complaining about redefinition of imports. And the resulting output files do have duplicated imports. For example:
$ openapi-python-client generate --meta none --url https://raw.githubusercontent.com/openapi-generators/openapi-python-client/main/end_to_end_tests/baseline_openapi_3.0.json
[...]
models/test_inline_objects_body.py:8:21: F811 Redefinition of unused `UNSET` from line 6
models/test_inline_objects_body.py:8:28: F811 Redefinition of unused `Unset` from line 6
models/test_inline_objects_response_200.py:8:21: F811 Redefinition of unused `UNSET` from line 6
models/test_inline_objects_response_200.py:8:28: F811 Redefinition of unused `Unset` from line 6
Found 640 errors (482 fixed, 158 remaining).
I think this is happening because with --meta none there's no pyproject.toml that turns on isort functionality in ruff. With the other --meta options, ruff gets configured with select = ["F", "I"], and this fixes the duplicate imports.
One solution would be to explicitly include ruff's isort rules when running ruff in the post hooks. I've found that the following config fixes the issue:
post_hooks:
- "ruff check . --fix --extend-select=I"
- "ruff format ."OpenAPI Spec File
This is reproducible with the openapi-python-client test specs, such as https://raw.githubusercontent.com/openapi-generators/openapi-python-client/main/end_to_end_tests/baseline_openapi_3.0.json.
Desktop (please complete the following information):
- OS: Debian Bookworm
- Python Version: 3.11.2
- openapi-python-client version 0.17.1