From 61629ae8ed3ae1d507127df0c6c6a754930adc68 Mon Sep 17 00:00:00 2001 From: Yohei Kitamura Date: Sat, 4 Nov 2023 04:54:17 -0400 Subject: [PATCH] [python] Add back `__enter__` and `__exit__` methods for non asyncio (#16979) --- .../src/main/resources/python/api_client.mustache | 7 +++++++ .../openapi_client/api_client.py | 5 +++++ .../client/echo_api/python/openapi_client/api_client.py | 5 +++++ .../client/petstore/python/petstore_api/api_client.py | 5 +++++ 4 files changed, 22 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/python/api_client.mustache b/modules/openapi-generator/src/main/resources/python/api_client.mustache index b041d86e52f..8df24870123 100644 --- a/modules/openapi-generator/src/main/resources/python/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/python/api_client.mustache @@ -92,6 +92,13 @@ class ApiClient: async def close(self): await self.rest_client.close() {{/asyncio}} +{{^asyncio}} + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_value, traceback): + pass +{{/asyncio}} @property def user_agent(self): diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent-true/openapi_client/api_client.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent-true/openapi_client/api_client.py index 665f8d49e26..d1063c0d147 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent-true/openapi_client/api_client.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent-true/openapi_client/api_client.py @@ -90,6 +90,11 @@ class ApiClient: self.user_agent = 'OpenAPI-Generator/1.0.0/python' self.client_side_validation = configuration.client_side_validation + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_value, traceback): + pass @property def user_agent(self): diff --git a/samples/client/echo_api/python/openapi_client/api_client.py b/samples/client/echo_api/python/openapi_client/api_client.py index 665f8d49e26..d1063c0d147 100644 --- a/samples/client/echo_api/python/openapi_client/api_client.py +++ b/samples/client/echo_api/python/openapi_client/api_client.py @@ -90,6 +90,11 @@ class ApiClient: self.user_agent = 'OpenAPI-Generator/1.0.0/python' self.client_side_validation = configuration.client_side_validation + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_value, traceback): + pass @property def user_agent(self): diff --git a/samples/openapi3/client/petstore/python/petstore_api/api_client.py b/samples/openapi3/client/petstore/python/petstore_api/api_client.py index 0a5d2cf2771..87f81c87199 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api_client.py @@ -89,6 +89,11 @@ class ApiClient: self.user_agent = 'OpenAPI-Generator/1.0.0/python' self.client_side_validation = configuration.client_side_validation + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_value, traceback): + pass @property def user_agent(self):