Bug Report Checklist
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 [email protected]:OpenAPITools/openapi-generator.git
cd openapi-generator/samples/client/echo_api/python
docker run -v .:/io --rm ghcr.io/astral-sh/ruff check --fix
actual 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
#21935
Suggest a fix
change == operator with issubclass() calls (it is already used for Enum type)
|
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) |
Bug Report Checklist
Description
Freshly created python api client doesn't pass style checks with fixes by
ruff.ruffis a popular tool for python linting and formatting.openapi-generator version
7.15.0
also current
masterOpenAPI declaration file content or url
from project samlpes
Generation Details
In python a preffered way to check types equality is using
isoperator or using aissubclass().Steps to reproduce
actual output:
elxpected output: all errors fixed
Related issues/PRs
#21935
Suggest a fix
change
==operator withissubclass()calls (it is already used forEnumtype)openapi-generator/modules/openapi-generator/src/main/resources/python/api_client.mustache
Lines 470 to 483 in 278d7ae