Skip to content

[Python] Adding type-hinting for API responses #841

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/resources/handlebars/python/__init__api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ from __future__ import absolute_import

# flake8: noqa

# Import models for type-hinting
{{#models}}{{#model}}from {{modelPackage}}.{{classFilename}} import {{classname}}
{{/model}}{{/models}}

# import apis into api package
{{#apiInfo}}{{#apis}}from {{importPath}} import {{classname}}
{{/apis}}{{/apiInfo}}
{{/apis}}{{/apiInfo}}
8 changes: 7 additions & 1 deletion src/main/resources/handlebars/python/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import re # noqa: F401

# python 2 and python 3 compatibility library
import six

# Model imports
{{#operations}}{{#operation}}{{#unless returnTypeIsPrimitive}}{{#returnType}}from . import {{returnType}}
{{/returnType}}{{/unless}}{{/operation}}{{/operations}}
# Importing for doctring purposes
# Api Client
from {{packageName}}.api_client import ApiClient


Expand Down Expand Up @@ -50,6 +54,7 @@ class {{classname}}(object):
:return: {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}
If the method is called asynchronously,
returns the request thread.
:rtype: {{#returnType}}{{returnType}} | {{/returnType}}multiprocessing.pool.ApplyResult
"""
kwargs['_return_http_data_only'] = True
if kwargs.get('async_req'):
Expand Down Expand Up @@ -81,6 +86,7 @@ class {{classname}}(object):
:return: {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}
If the method is called asynchronously,
returns the request thread.
:rtype: {{#returnType}}{{returnType}} | {{/returnType}}multiprocessing.pool.ApplyResult
"""

all_params = [{{#parameters}}'{{paramName}}'{{#hasMore}}, {{/hasMore}}{{/parameters}}] # noqa: E501
Expand Down