Skip to content

Typing error in generated client when response attribute use reserved keywords #359

Closed
@dblanchette

Description

@dblanchette

Describe the bug
I am using this library to generate a Python client for Jira using their OpenAPI spec.

I get a strange bug at import time:

  File "D:\Repos\jira_generated\the-jira-cloud-platform-rest-api-client\the_jira_cloud_platform_rest_api_client\models\json_node.py", line 38, in JsonNode
    int_value: Union[Unset, int] = UNSET
  File "C:\Apps\Python38\lib\typing.py", line 261, in inner
    return func(*args, **kwds)
  File "C:\Apps\Python38\lib\typing.py", line 358, in __getitem__
    parameters = tuple(_type_check(p, msg) for p in parameters)
  File "C:\Apps\Python38\lib\typing.py", line 358, in <genexpr>
    parameters = tuple(_type_check(p, msg) for p in parameters)
  File "C:\Apps\Python38\lib\typing.py", line 149, in _type_check
    raise TypeError(f"{msg} Got {arg!r:.100}.")
TypeError: Union[arg, ...]: each arg must be a type. Got <the_jira_cloud_platform_rest_api_client.types.Unset object at 0x0000018CF4EEA070>.

After investigating for a while, I came to the conclusion that it's because the JsonNode object has an attribute named "int". The attribute shadows the built-in name int and causes type hinting to fail:

@attr.s(auto_attribs=True)
class JsonNode:
    """  """

    ... # Other attributes
    int: Union[Unset, bool] = UNSET
    ... # Other attributes
    int_value: Union[Unset, int] = UNSET  # Breaks here!
    ... # Other attributes

To Reproduce
Steps to reproduce the behavior:

  1. Generate the client for Jira: openapi-python-client generate --url https://developer.atlassian.com/cloud/jira/platform/swagger-v3.v3.json
  2. cd to the generated directory and open a Python shell
  3. Import get_changelogs: from the_jira_cloud_platform_rest_api_client.api.issues import get_change_logs or anything else indirectly using JsonNode

Expected behavior
A different name may need to be used here like int_ or similar.

OpenAPI Spec File
https://developer.atlassian.com/cloud/jira/platform/swagger-v3.v3.json

Desktop (please complete the following information):

  • OS: Windows 10
  • Python Version: 3.8.8
  • openapi-python-client version: 0.8.0

Additional context
Thanks for the great tool!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions