Bug Report Checklist
Description
The generated api clients of the Python module produce a __init__ method which has type hints for all its parameters, but is missing the return type annotation.
E.g.: https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/echo_api/python/openapi_client/api/body_api.py#L45
Creating an instance of the said class and then run mypy over the file will result in the following error:
error: Call to untyped function "BodyApi" in typed context [no-untyped-call]
openapi-generator version
7.0.0
OpenAPI declaration file content or url
I used the sample code as an example: https://github.com/OpenAPITools/openapi-generator/tree/master/samples/client/echo_api/python
Generation Details
¯_(ツ)_/¯
Steps to reproduce
- Checkout the repository
cd to: samples/client/echo_api/python
- Change the supported
python version to at least 3.8
- Create a new directory in
samples/client/echo_api/python_test
- Create a
pyproject.toml with the following contents:
[tool.poetry]
name = "python-test"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.10"
openapi-client = {path = "../python"}
[tool.poetry.group.dev.dependencies]
mypy = "^1.5.1"
[tool.mypy]
strict = true
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
- Create a
test.py with the follwing contents:
from openapi_client.api.body_api import BodyApi
body_api = BodyApi()
- Call
poetry run mypy test.py
Suggest a fix
Simply adding -> None as the return type of the __init__ function solves the problem.
Assuming you have the Steps to reproduce done:
- Create the following diff:
diff --git a/samples/client/echo_api/python/openapi_client/api/body_api.py b/samples/client/echo_api/python/openapi_client/api/body_api.py
index fa1953cecd3..e07517d2920 100644
--- a/samples/client/echo_api/python/openapi_client/api/body_api.py
+++ b/samples/client/echo_api/python/openapi_client/api/body_api.py
@@ -42,7 +42,7 @@ class BodyApi(object):
Do not edit the class manually.
"""
- def __init__(self, api_client=None):
+ def __init__(self, api_client=None) -> None:
if api_client is None:
api_client = ApiClient.get_default()
self.api_client = api_client
Bug Report Checklist
Description
The generated
apiclients of thePythonmodule produce a__init__method which has type hints for all its parameters, but is missing the return type annotation.E.g.: https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/echo_api/python/openapi_client/api/body_api.py#L45
Creating an instance of the said class and then run mypy over the file will result in the following error:
openapi-generator version
7.0.0OpenAPI declaration file content or url
I used the sample code as an example: https://github.com/OpenAPITools/openapi-generator/tree/master/samples/client/echo_api/python
Generation Details
¯_(ツ)_/¯
Steps to reproduce
cdto:samples/client/echo_api/pythonpythonversion to at least3.8samples/client/echo_api/python_testpyproject.tomlwith the following contents:test.pywith the follwing contents:poetry run mypy test.pySuggest a fix
Simply adding
-> Noneas the return type of the__init__function solves the problem.Assuming you have the
Steps to reproducedone: