Skip to content

[BUG] Python client doesn't pass style checks #21936

Closed

Description

@artem-ilin

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 --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)

Activity

  1. added 3 commits that reference this issue on Sep 9, 2025
    2dcb9c5
    0e0262d
    11bd615
  2. added a commit that references this issue on Sep 10, 2025
    5f647b8
  3. added a commit that references this issue on Sep 16, 2025
    18395da
  4. added a commit that references this issue on Dec 25, 2025
    f34fe7f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions