-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[REQ] Python Improved Model Template #4807
Comments
@MikeMcGarry the python-experimental model classes have description of their class variables and the arg required and optional kwarg inputs for the model. See an example here: Does that meet your needs?If so, we may want to also use that code in the python client. Detailed python-experimental infoIn python-experimental:
Operation examples:
Note: we also standardized how we access allowed_values in models and endpoints in that generator. |
Related: #4600 |
After trying to generate a python model for a new project using the 4.3.1 generator, and finding it to be less than good, I tried using the 5.0.0 generator only to find it's drastically worse. With the 4.3.1 generator So basically in 4.3.1, the IDE at least had some idea that these arguments & properties existed, even if it didn't know the type. Now it has no clue. If we're going to continue with this metaprogramming design, can we at least generate stub files to address the issue? |
We welcome any prs which will add type definition to the signatures of the methods and functions in the python generators and alow for static analysis. We also welcome any PRs which add stubs or attribute accessors which help IDEs. Also the Python generator is using strict typing for model instance inputs and endpoint inputs and responses so if a type is wrong an error will be thrown. Optional arguments were moved into kwargs because they can be nullable. The old way would look like:
With the original function signature, in the endpoint function client side we had no way to tell use case 1 + 2 apart because the code was using a value of None to check if a value had been assigned. |
@phemmer what IDE are you using? |
IntelliJ IDEA/PyCharm |
Note that the limitation of the number of arguments no longer exists in Python 3.7+ And with Python 3.6 going end of life in less than 2 months, this concern may be less of a concern: https://endoflife.date/python |
Heads up. We now have a new generator, python-experimental which has type hints for instantiating models and for endpoint parameters. It was added in: #8325 |
Closing this issue because the python-experimental generator includes the requested model type hints in the model
|
Is your feature request related to a problem? Please describe.
When using an IDE e.g. PyCharm with SDKs generated using the openapi-generator in Python. The docstring in the "init" method for any models is next to useless. All it says by default is
"""{modelName} - a model defined in OpenAPI". """
There is therefore little value in the type hints and docstring when developing using an IDE.
In addition there is no way to easily tell the difference between the required and optional parameters outside of looking at the setters and if they have a None check.
Describe the solution you'd like
It would be great to have a docstring with the parameter descriptions and types which helps with using the SDK.
For example (a snippet from our LUSID Python SDK):
Would come from the following template:
It would also be great to have a required_map which notes down which attributes are required and optional.
E.g:
Which would come from the following in the template:
Describe alternatives you've considered
We were able to solve both these issues with a custom template. I think the custom template we created is generic enough to be used as the default model template and want to see if we should merge it in.
The text was updated successfully, but these errors were encountered: