From 8c0c97f46246bb7fdb0c6c470e4ef7981dc079ae Mon Sep 17 00:00:00 2001 From: Colossal Code <54778962+colossal-code@users.noreply.github.com> Date: Tue, 29 Oct 2019 18:13:23 +0530 Subject: [PATCH] [Python] [Performance] Avoid unnessacary checks inside the loop --- .../src/main/resources/python/api_client.mustache | 8 ++++---- .../petstore/python-asyncio/petstore_api/api_client.py | 8 ++++---- .../petstore/python-tornado/petstore_api/api_client.py | 8 ++++---- samples/client/petstore/python/petstore_api/api_client.py | 8 ++++---- .../client/petstore/python/petstore_api/api_client.py | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) 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 63dd91ebb5d9..4b5661a9b636 100644 --- a/modules/openapi-generator/src/main/resources/python/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/python/api_client.mustache @@ -629,11 +629,11 @@ class ApiClient(object): return data kwargs = {} - if klass.openapi_types is not None: + if (data is not None and + klass.openapi_types is not None and + isinstance(data, (list, dict))): for attr, attr_type in six.iteritems(klass.openapi_types): - if (data is not None and - klass.attribute_map[attr] in data and - isinstance(data, (list, dict))): + if klass.attribute_map[attr] in data: value = data[klass.attribute_map[attr]] kwargs[attr] = self.__deserialize(value, attr_type) diff --git a/samples/client/petstore/python-asyncio/petstore_api/api_client.py b/samples/client/petstore/python-asyncio/petstore_api/api_client.py index 0405206d9829..14cb7ac44fd2 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/api_client.py +++ b/samples/client/petstore/python-asyncio/petstore_api/api_client.py @@ -622,11 +622,11 @@ def __deserialize_model(self, data, klass): return data kwargs = {} - if klass.openapi_types is not None: + if (data is not None and + klass.openapi_types is not None and + isinstance(data, (list, dict))): for attr, attr_type in six.iteritems(klass.openapi_types): - if (data is not None and - klass.attribute_map[attr] in data and - isinstance(data, (list, dict))): + if klass.attribute_map[attr] in data: value = data[klass.attribute_map[attr]] kwargs[attr] = self.__deserialize(value, attr_type) diff --git a/samples/client/petstore/python-tornado/petstore_api/api_client.py b/samples/client/petstore/python-tornado/petstore_api/api_client.py index 6824bec06ef5..37342f0e0e54 100644 --- a/samples/client/petstore/python-tornado/petstore_api/api_client.py +++ b/samples/client/petstore/python-tornado/petstore_api/api_client.py @@ -624,11 +624,11 @@ def __deserialize_model(self, data, klass): return data kwargs = {} - if klass.openapi_types is not None: + if (data is not None and + klass.openapi_types is not None and + isinstance(data, (list, dict))): for attr, attr_type in six.iteritems(klass.openapi_types): - if (data is not None and - klass.attribute_map[attr] in data and - isinstance(data, (list, dict))): + if klass.attribute_map[attr] in data: value = data[klass.attribute_map[attr]] kwargs[attr] = self.__deserialize(value, attr_type) diff --git a/samples/client/petstore/python/petstore_api/api_client.py b/samples/client/petstore/python/petstore_api/api_client.py index f9c494a76c36..2086695a029b 100644 --- a/samples/client/petstore/python/petstore_api/api_client.py +++ b/samples/client/petstore/python/petstore_api/api_client.py @@ -622,11 +622,11 @@ def __deserialize_model(self, data, klass): return data kwargs = {} - if klass.openapi_types is not None: + if (data is not None and + klass.openapi_types is not None and + isinstance(data, (list, dict))): for attr, attr_type in six.iteritems(klass.openapi_types): - if (data is not None and - klass.attribute_map[attr] in data and - isinstance(data, (list, dict))): + if klass.attribute_map[attr] in data: value = data[klass.attribute_map[attr]] kwargs[attr] = self.__deserialize(value, attr_type) 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 f9c494a76c36..2086695a029b 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api_client.py @@ -622,11 +622,11 @@ def __deserialize_model(self, data, klass): return data kwargs = {} - if klass.openapi_types is not None: + if (data is not None and + klass.openapi_types is not None and + isinstance(data, (list, dict))): for attr, attr_type in six.iteritems(klass.openapi_types): - if (data is not None and - klass.attribute_map[attr] in data and - isinstance(data, (list, dict))): + if klass.attribute_map[attr] in data: value = data[klass.attribute_map[attr]] kwargs[attr] = self.__deserialize(value, attr_type)