Repository navigation
[BUG] Python client doesn't pass style checks #21936
Copy link
Copy link
Closed
Labels
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Freshly created python api client doesn't pass style checks with fixes by ruff. ruff is a popular tool for python linting and formatting.
openapi-generator version
7.15.0
also current master
OpenAPI declaration file content or url
from project samlpes
Generation Details
In python a preffered way to check types equality is using is operator or using a issubclass().
>>> class T(str): ...
>>> T == str
False
>>> T is str
False
>>> str == str
True
>>> str is str
True
>>> issubclass(T, str)
True
>>> issubclass(str, str)
True
>>>
Steps to reproduce
git clone git@github.com:OpenAPITools/openapi-generator.git
cd openapi-generator/samples/client/echo_api/python
docker run -v .:/io --rm ghcr.io/astral-sh/ruff check --fixactual output:
warning: Invalid rule code provided to `# noqa` at setup.py:16: H301
E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
--> openapi_client/api_client.py:459:14
|
457 | if klass in self.PRIMITIVE_TYPES:
458 | return self.__deserialize_primitive(data, klass)
459 | elif klass == object:
| ^^^^^^^^^^^^^^^
460 | return self.__deserialize_object(data)
461 | elif klass == datetime.date:
|
Found 56 errors (55 fixed, 1 remaining).
elxpected output: all errors fixed
Related issues/PRs
Suggest a fix
change == operator with issubclass() calls (it is already used for Enum type)
openapi-generator/modules/openapi-generator/src/main/resources/python/api_client.mustache
Lines 470 to 483 in 278d7ae
| if klass in self.PRIMITIVE_TYPES: | |
| return self.__deserialize_primitive(data, klass) | |
| elif klass == object: | |
| return self.__deserialize_object(data) | |
| elif klass == datetime.date: | |
| return self.__deserialize_date(data) | |
| elif klass == datetime.datetime: | |
| return self.__deserialize_datetime(data) | |
| elif klass == decimal.Decimal: | |
| return decimal.Decimal(data) | |
| elif issubclass(klass, Enum): | |
| return self.__deserialize_enum(data, klass) | |
| else: | |
| return self.__deserialize_model(data, klass) |
Reactions are currently unavailable
Activity
[python] fixes OpenAPITools#21936, api client type checks
[python] fixes OpenAPITools#21936, api client type checks
[python] fixes OpenAPITools#21936, api client type checks
[python] fixes #21936, api client type checks (#21935)
[python] fixes OpenAPITools#21936, api client type checks (OpenAPIToo…
[python] fixes OpenAPITools#21936, api client type checks (OpenAPIToo…