Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dblanchette opened this issue Mar 23, 2021 · 1 comment · Fixed by #360
Closed
Labels
🐞bug Something isn't working 👋 good first issue Good for newcomers

Comments

@dblanchette
Copy link
Contributor

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!

@dblanchette dblanchette added the 🐞bug Something isn't working label Mar 23, 2021
@dbanty
Copy link
Collaborator

dbanty commented Mar 23, 2021

Thanks for reporting! We currently have utilities for stripping out keywords as well as some custom reserved words in openapi_python_client/utils.py . This doesn't check for builtins just yet, my guess is we need to do something like:

import builtins

RESERVED_WORDS = set(dir(builtins))

@dbanty dbanty added the 👋 good first issue Good for newcomers label Mar 23, 2021
dblanchette added a commit to coveord/openapi-python-client that referenced this issue Mar 23, 2021
dblanchette added a commit to coveord/openapi-python-client that referenced this issue Mar 23, 2021
dblanchette added a commit to coveord/openapi-python-client that referenced this issue Mar 23, 2021
dblanchette added a commit to coveord/openapi-python-client that referenced this issue Mar 23, 2021
dbanty pushed a commit that referenced this issue Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞bug Something isn't working 👋 good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants