From 5bf78a4b2d12b60a92606b0597b04510e576fff4 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 21 May 2020 17:59:50 -0400 Subject: [PATCH 1/8] optional response type --- autorest/codegen/models/operation.py | 16 +++++++++ .../codegen/templates/operation_tools.jinja2 | 8 ++--- .../_lros_operations_async.py | 36 +++++++++---------- .../_lrosads_operations_async.py | 6 ++-- .../Lro/lro/operations/_lros_operations.py | 24 ++++++------- .../Lro/lro/operations/_lrosads_operations.py | 4 +-- .../_storage_accounts_operations_async.py | 6 ++-- .../_storage_accounts_operations.py | 4 +-- .../multiapi/aio/_operations_mixin_async.py | 2 +- .../Multiapi/multiapi/v1/_metadata.json | 4 +-- ...ultiapi_service_client_operations_async.py | 6 ++-- .../_multiapi_service_client_operations.py | 4 +-- .../multiapinoasync/v1/_metadata.json | 4 +-- .../_multiapi_service_client_operations.py | 4 +-- .../submodule/aio/_operations_mixin_async.py | 2 +- .../submodule/v1/_metadata.json | 4 +-- ...ultiapi_service_client_operations_async.py | 6 ++-- .../_multiapi_service_client_operations.py | 4 +-- .../_http_redirects_operations_async.py | 2 +- .../_multiple_responses_operations_async.py | 10 +++--- .../operations/_http_redirects_operations.py | 2 +- .../_multiple_responses_operations.py | 10 +++--- .../operations_async/_pet_operations_async.py | 2 +- .../operations/_pet_operations.py | 2 +- 24 files changed, 94 insertions(+), 78 deletions(-) diff --git a/autorest/codegen/models/operation.py b/autorest/codegen/models/operation.py index 10938b6b9b7..7066dcb91cc 100644 --- a/autorest/codegen/models/operation.py +++ b/autorest/codegen/models/operation.py @@ -165,6 +165,22 @@ def is_stream_response(self) -> bool: """Is the response expected to be streamable, like a download.""" return any(response.is_stream_response for response in self.responses) + @property + def has_optional_return_type(self) -> bool: + """Has optional return type if there are multiple response types where some have bodies and some are None""" + + # successful status codes of responses that have bodies + status_codes_for_responses_with_bodies = [ + code for code in self.success_status_code + if self.get_response_from_status(code).has_body + ] + + if self.has_response_body and len(self.responses) > 1: + if len(self.success_status_code) != len(status_codes_for_responses_with_bodies): + return True + return False + + @staticmethod def build_serialize_data_call(parameter: Parameter, function_name: str) -> str: diff --git a/autorest/codegen/templates/operation_tools.jinja2 b/autorest/codegen/templates/operation_tools.jinja2 index c11bd91c041..11912e8c9bf 100644 --- a/autorest/codegen/templates/operation_tools.jinja2 +++ b/autorest/codegen/templates/operation_tools.jinja2 @@ -2,7 +2,7 @@ {% macro return_docstring(operation) %} {% if operation.responses | selectattr('has_body') | first %} :return: {{ operation.responses|selectattr('has_body')|map(attribute='schema')| map(attribute='docstring_text')|unique|join(' or ') }}, or the result of cls(response) -:rtype: {{ operation.responses|selectattr('has_body')|map(attribute='schema')| map(attribute='docstring_type')|unique|join(' or ') }}{{ " or None" if operation.responses|selectattr('has_body', 'false') | first }} +:rtype: {{ operation.responses|selectattr('has_body')|map(attribute='schema')| map(attribute='docstring_type')|unique|join(' or ') }}{{ " or None" if operation.has_optional_return_type }} {%- else %} :return: None, or the result of cls(response) :rtype: None @@ -37,11 +37,11 @@ :raises: ~azure.core.exceptions.HttpResponseError """{% endmacro %} {% macro return_type_annotation(operation, return_type_wrapper) %} -{{ ((return_type_wrapper + "[") if return_type_wrapper else "") ~ ("Union[" if operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation') | unique | list | length > 1 else "") ~ +{{ ("Optional[" if operation.has_optional_return_type and not return_type_wrapper else "" ) ~ ((return_type_wrapper + "[") if return_type_wrapper else "") ~ ("Union[" if operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation') | unique | list | length > 1 else "") ~ (operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation') | unique | join(', ')) ~ -("]" if operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation')| unique | list | length > 1 else "") ~ ( "]" if return_type_wrapper else "") +("]" if operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation')| unique | list | length > 1 else "") ~ ( "]" if return_type_wrapper else "") ~ ("]" if operation.has_optional_return_type and not return_type_wrapper else "") if operation.responses | selectattr('has_body') | first -else ((return_type_wrapper + "[") if return_type_wrapper else "") ~ "None" ~ ( "]" if return_type_wrapper else "") }}{% endmacro %} +else ("Optional[" if operation.has_optional_return_type and not return_type_wrapper else "" ) ~ ((return_type_wrapper + "[") if return_type_wrapper else "") ~ "None" ~ ( "]" if return_type_wrapper else "") ~ ("]" if operation.has_optional_return_type and not return_type_wrapper else "") }}{% endmacro %} {# get async mypy typing #} {% macro async_return_type_annotation(operation, return_type_wrapper) %} {{ " -> " + return_type_annotation(operation, return_type_wrapper) }}{% endmacro %} diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lros_operations_async.py b/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lros_operations_async.py index d00b089f273..ff5e271b8e9 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lros_operations_async.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lros_operations_async.py @@ -47,7 +47,7 @@ async def _put200_succeeded_initial( self, product: Optional["models.Product"] = None, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -95,7 +95,7 @@ async def put200_succeeded( self, product: Optional["models.Product"] = None, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: """Long running put request, service returns a 200 to the initial request, with an entity that contains ProvisioningState=’Succeeded’. @@ -111,7 +111,7 @@ async def put200_succeeded( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -234,7 +234,7 @@ def get_long_running_output(pipeline_response): async def _post202_list_initial( self, **kwargs - ) -> List["models.Product"]: + ) -> Optional[List["models.Product"]]: cls = kwargs.pop('cls', None) # type: ClsType[List["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -277,7 +277,7 @@ async def _post202_list_initial( async def post202_list( self, **kwargs - ) -> List["models.Product"]: + ) -> Optional[List["models.Product"]]: """Long running put request, service returns a 202 with empty body to first request, returns a 200 with body [{ 'id': '100', 'name': 'foo' }]. @@ -291,7 +291,7 @@ async def post202_list( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[List["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType[Optional[List["models.Product"]]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -2217,7 +2217,7 @@ def get_long_running_output(pipeline_response): async def _delete202_retry200_initial( self, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -2260,7 +2260,7 @@ async def _delete202_retry200_initial( async def delete202_retry200( self, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: """Long running delete request, service returns a 202 to the initial request. Polls return this value until the last poll returns a ‘200’ with ProvisioningState=’Succeeded’. @@ -2274,7 +2274,7 @@ async def delete202_retry200( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -2303,7 +2303,7 @@ def get_long_running_output(pipeline_response): async def _delete202_no_retry204_initial( self, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -2346,7 +2346,7 @@ async def _delete202_no_retry204_initial( async def delete202_no_retry204( self, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: """Long running delete request, service returns a 202 to the initial request. Polls return this value until the last poll returns a ‘200’ with ProvisioningState=’Succeeded’. @@ -2360,7 +2360,7 @@ async def delete202_no_retry204( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -3364,7 +3364,7 @@ async def _post_async_retry_succeeded_initial( self, product: Optional["models.Product"] = None, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -3418,7 +3418,7 @@ async def post_async_retry_succeeded( self, product: Optional["models.Product"] = None, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: """Long running post request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -3435,7 +3435,7 @@ async def post_async_retry_succeeded( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -3466,7 +3466,7 @@ async def _post_async_no_retry_succeeded_initial( self, product: Optional["models.Product"] = None, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -3520,7 +3520,7 @@ async def post_async_no_retry_succeeded( self, product: Optional["models.Product"] = None, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: """Long running post request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -3537,7 +3537,7 @@ async def post_async_no_retry_succeeded( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lrosads_operations_async.py b/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lrosads_operations_async.py index 68ac4526153..2dd22d05db2 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lrosads_operations_async.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lrosads_operations_async.py @@ -1571,7 +1571,7 @@ async def _put200_invalid_json_initial( self, product: Optional["models.Product"] = None, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -1619,7 +1619,7 @@ async def put200_invalid_json( self, product: Optional["models.Product"] = None, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: """Long running put request, service returns a 200 to the initial request, with an entity that is not a valid json. @@ -1635,7 +1635,7 @@ async def put200_invalid_json( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lros_operations.py b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lros_operations.py index ad40f1fd5a4..999d9ab7230 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lros_operations.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lros_operations.py @@ -52,7 +52,7 @@ def _put200_succeeded_initial( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> "models.Product" + # type: (...) -> Optional["models.Product"] cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -117,7 +117,7 @@ def begin_put200_succeeded( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -243,7 +243,7 @@ def _post202_list_initial( self, **kwargs # type: Any ): - # type: (...) -> List["models.Product"] + # type: (...) -> Optional[List["models.Product"]] cls = kwargs.pop('cls', None) # type: ClsType[List["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -301,7 +301,7 @@ def begin_post202_list( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[List["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType[Optional[List["models.Product"]]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -2268,7 +2268,7 @@ def _delete202_retry200_initial( self, **kwargs # type: Any ): - # type: (...) -> "models.Product" + # type: (...) -> Optional["models.Product"] cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -2326,7 +2326,7 @@ def begin_delete202_retry200( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -2356,7 +2356,7 @@ def _delete202_no_retry204_initial( self, **kwargs # type: Any ): - # type: (...) -> "models.Product" + # type: (...) -> Optional["models.Product"] cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -2414,7 +2414,7 @@ def begin_delete202_no_retry204( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -3443,7 +3443,7 @@ def _post_async_retry_succeeded_initial( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> "models.Product" + # type: (...) -> Optional["models.Product"] cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -3515,7 +3515,7 @@ def begin_post_async_retry_succeeded( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -3547,7 +3547,7 @@ def _post_async_no_retry_succeeded_initial( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> "models.Product" + # type: (...) -> Optional["models.Product"] cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -3619,7 +3619,7 @@ def begin_post_async_no_retry_succeeded( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lrosads_operations.py b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lrosads_operations.py index 8fe55082e2d..9c70c3b1404 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lrosads_operations.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lrosads_operations.py @@ -1610,7 +1610,7 @@ def _put200_invalid_json_initial( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> "models.Product" + # type: (...) -> Optional["models.Product"] cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -1675,7 +1675,7 @@ def begin_put200_invalid_json( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/azure/Expected/AcceptanceTests/StorageManagementClient/storage/aio/operations_async/_storage_accounts_operations_async.py b/test/azure/Expected/AcceptanceTests/StorageManagementClient/storage/aio/operations_async/_storage_accounts_operations_async.py index 759d38466e4..24c0caafb0e 100644 --- a/test/azure/Expected/AcceptanceTests/StorageManagementClient/storage/aio/operations_async/_storage_accounts_operations_async.py +++ b/test/azure/Expected/AcceptanceTests/StorageManagementClient/storage/aio/operations_async/_storage_accounts_operations_async.py @@ -111,7 +111,7 @@ async def _create_initial( account_name: str, parameters: "models.StorageAccountCreateParameters", **kwargs - ) -> "models.StorageAccount": + ) -> Optional["models.StorageAccount"]: cls = kwargs.pop('cls', None) # type: ClsType["models.StorageAccount"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -166,7 +166,7 @@ async def create( account_name: str, parameters: "models.StorageAccountCreateParameters", **kwargs - ) -> "models.StorageAccount": + ) -> Optional["models.StorageAccount"]: """Asynchronously creates a new storage account with the specified parameters. Existing accounts cannot be updated with this API and should instead use the Update Storage Account API. If an account is already created and subsequent PUT request is issued with exact same set of @@ -190,7 +190,7 @@ async def create( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.StorageAccount"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.StorageAccount"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/azure/Expected/AcceptanceTests/StorageManagementClient/storage/operations/_storage_accounts_operations.py b/test/azure/Expected/AcceptanceTests/StorageManagementClient/storage/operations/_storage_accounts_operations.py index 4b90634be09..12d22d6f4c3 100644 --- a/test/azure/Expected/AcceptanceTests/StorageManagementClient/storage/operations/_storage_accounts_operations.py +++ b/test/azure/Expected/AcceptanceTests/StorageManagementClient/storage/operations/_storage_accounts_operations.py @@ -116,7 +116,7 @@ def _create_initial( parameters, # type: "models.StorageAccountCreateParameters" **kwargs # type: Any ): - # type: (...) -> "models.StorageAccount" + # type: (...) -> Optional["models.StorageAccount"] cls = kwargs.pop('cls', None) # type: ClsType["models.StorageAccount"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -196,7 +196,7 @@ def begin_create( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.StorageAccount"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.StorageAccount"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/aio/_operations_mixin_async.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/aio/_operations_mixin_async.py index 2643b77915a..92905d0f4ec 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/aio/_operations_mixin_async.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/aio/_operations_mixin_async.py @@ -24,7 +24,7 @@ async def test_lro( self, product: Optional["models.Product"] = None, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: """Put in whatever shape of Product you want, will return a Product with id equal to 100. :param product: Product to put. diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/_metadata.json b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/_metadata.json index da28e75e0f7..40f24305206 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/_metadata.json @@ -55,7 +55,7 @@ }, "async": { "operation_name": "_test_lro_initial", - "signature": "async def _test_lro_initial(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e \"models.Product\":\n", + "signature": "async def _test_lro_initial(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"models.Product\"]:\n", "coroutine": true }, "doc": " \"\"\"\n\n:param product: Product to put.\n:type product: ~multiapi.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapi.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"", @@ -68,7 +68,7 @@ }, "async": { "operation_name": "test_lro", - "signature": "async def test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e \"models.Product\":\n", + "signature": "async def test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"models.Product\"]:\n", "coroutine": true }, "doc": " \"\"\"Put in whatever shape of Product you want, will return a Product with id equal to 100.\n\n:param product: Product to put.\n:type product: ~multiapi.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapi.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"", diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/aio/operations_async/_multiapi_service_client_operations_async.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/aio/operations_async/_multiapi_service_client_operations_async.py index d5c0d0fbdd8..a682ff2a578 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/aio/operations_async/_multiapi_service_client_operations_async.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/aio/operations_async/_multiapi_service_client_operations_async.py @@ -75,7 +75,7 @@ async def _test_lro_initial( self, product: Optional["models.Product"] = None, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -123,7 +123,7 @@ async def test_lro( self, product: Optional["models.Product"] = None, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: """Put in whatever shape of Product you want, will return a Product with id equal to 100. :param product: Product to put. @@ -138,7 +138,7 @@ async def test_lro( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', False) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/operations/_multiapi_service_client_operations.py index 7022122ecc6..27f120de17e 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/operations/_multiapi_service_client_operations.py @@ -81,7 +81,7 @@ def _test_lro_initial( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> "models.Product" + # type: (...) -> Optional["models.Product"] cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -145,7 +145,7 @@ def begin_test_lro( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', False) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/_metadata.json b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/_metadata.json index 13d316b5b54..f97fda8692e 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/_metadata.json @@ -55,7 +55,7 @@ }, "async": { "operation_name": "_test_lro_initial", - "signature": "async def _test_lro_initial(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e \"models.Product\":\n", + "signature": "async def _test_lro_initial(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"models.Product\"]:\n", "coroutine": true }, "doc": " \"\"\"\n\n:param product: Product to put.\n:type product: ~multiapinoasync.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapinoasync.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"", @@ -68,7 +68,7 @@ }, "async": { "operation_name": "test_lro", - "signature": "async def test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e \"models.Product\":\n", + "signature": "async def test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"models.Product\"]:\n", "coroutine": true }, "doc": " \"\"\"Put in whatever shape of Product you want, will return a Product with id equal to 100.\n\n:param product: Product to put.\n:type product: ~multiapinoasync.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapinoasync.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"", diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/operations/_multiapi_service_client_operations.py index aec83d743b0..634d0d1fb91 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/operations/_multiapi_service_client_operations.py @@ -81,7 +81,7 @@ def _test_lro_initial( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> "models.Product" + # type: (...) -> Optional["models.Product"] cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -145,7 +145,7 @@ def begin_test_lro( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', False) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/aio/_operations_mixin_async.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/aio/_operations_mixin_async.py index 11552e376da..378c33d65c3 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/aio/_operations_mixin_async.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/aio/_operations_mixin_async.py @@ -24,7 +24,7 @@ async def test_lro( self, product: Optional["models.Product"] = None, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: """Put in whatever shape of Product you want, will return a Product with id equal to 100. :param product: Product to put. diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/_metadata.json b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/_metadata.json index 76bbd74decf..96a6ab11dce 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/_metadata.json @@ -55,7 +55,7 @@ }, "async": { "operation_name": "_test_lro_initial", - "signature": "async def _test_lro_initial(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e \"models.Product\":\n", + "signature": "async def _test_lro_initial(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"models.Product\"]:\n", "coroutine": true }, "doc": " \"\"\"\n\n:param product: Product to put.\n:type product: ~multiapiwithsubmodule.submodule.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapiwithsubmodule.submodule.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"", @@ -68,7 +68,7 @@ }, "async": { "operation_name": "test_lro", - "signature": "async def test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e \"models.Product\":\n", + "signature": "async def test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"models.Product\"]:\n", "coroutine": true }, "doc": " \"\"\"Put in whatever shape of Product you want, will return a Product with id equal to 100.\n\n:param product: Product to put.\n:type product: ~multiapiwithsubmodule.submodule.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapiwithsubmodule.submodule.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"", diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/aio/operations_async/_multiapi_service_client_operations_async.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/aio/operations_async/_multiapi_service_client_operations_async.py index 1ecf28682de..b963bc4303b 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/aio/operations_async/_multiapi_service_client_operations_async.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/aio/operations_async/_multiapi_service_client_operations_async.py @@ -75,7 +75,7 @@ async def _test_lro_initial( self, product: Optional["models.Product"] = None, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -123,7 +123,7 @@ async def test_lro( self, product: Optional["models.Product"] = None, **kwargs - ) -> "models.Product": + ) -> Optional["models.Product"]: """Put in whatever shape of Product you want, will return a Product with id equal to 100. :param product: Product to put. @@ -138,7 +138,7 @@ async def test_lro( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', False) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/operations/_multiapi_service_client_operations.py index 65a9decd18f..7ce6942377a 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/operations/_multiapi_service_client_operations.py @@ -81,7 +81,7 @@ def _test_lro_initial( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> "models.Product" + # type: (...) -> Optional["models.Product"] cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -145,7 +145,7 @@ def begin_test_lro( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', False) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_http_redirects_operations_async.py b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_http_redirects_operations_async.py index d47b87c797d..69b46c7e64f 100644 --- a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_http_redirects_operations_async.py +++ b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_http_redirects_operations_async.py @@ -88,7 +88,7 @@ async def head300( async def get300( self, **kwargs - ) -> List[str]: + ) -> Optional[List[str]]: """Return 300 status code and redirect to /http/success/200. :keyword callable cls: A custom type or function that will be passed the direct response diff --git a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_multiple_responses_operations_async.py b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_multiple_responses_operations_async.py index eee73fdcbb1..e48e4ae855e 100644 --- a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_multiple_responses_operations_async.py +++ b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_multiple_responses_operations_async.py @@ -44,7 +44,7 @@ def __init__(self, client, config, serializer, deserializer) -> None: async def get200_model204_no_model_default_error200_valid( self, **kwargs - ) -> "models.MyException": + ) -> Optional["models.MyException"]: """Send a 200 response with valid payload: {'statusCode': '200'}. :keyword callable cls: A custom type or function that will be passed the direct response @@ -90,7 +90,7 @@ async def get200_model204_no_model_default_error200_valid( async def get200_model204_no_model_default_error204_valid( self, **kwargs - ) -> "models.MyException": + ) -> Optional["models.MyException"]: """Send a 204 response with no payload. :keyword callable cls: A custom type or function that will be passed the direct response @@ -136,7 +136,7 @@ async def get200_model204_no_model_default_error204_valid( async def get200_model204_no_model_default_error201_invalid( self, **kwargs - ) -> "models.MyException": + ) -> Optional["models.MyException"]: """Send a 201 response with valid payload: {'statusCode': '201'}. :keyword callable cls: A custom type or function that will be passed the direct response @@ -182,7 +182,7 @@ async def get200_model204_no_model_default_error201_invalid( async def get200_model204_no_model_default_error202_none( self, **kwargs - ) -> "models.MyException": + ) -> Optional["models.MyException"]: """Send a 202 response with no payload:. :keyword callable cls: A custom type or function that will be passed the direct response @@ -228,7 +228,7 @@ async def get200_model204_no_model_default_error202_none( async def get200_model204_no_model_default_error400_valid( self, **kwargs - ) -> "models.MyException": + ) -> Optional["models.MyException"]: """Send a 400 response with valid error payload: {'status': 400, 'message': 'client error'}. :keyword callable cls: A custom type or function that will be passed the direct response diff --git a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_http_redirects_operations.py b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_http_redirects_operations.py index 77a226d12b6..c9b72655aa0 100644 --- a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_http_redirects_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_http_redirects_operations.py @@ -94,7 +94,7 @@ def get300( self, **kwargs # type: Any ): - # type: (...) -> List[str] + # type: (...) -> Optional[List[str]] """Return 300 status code and redirect to /http/success/200. :keyword callable cls: A custom type or function that will be passed the direct response diff --git a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_multiple_responses_operations.py b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_multiple_responses_operations.py index 0cb38f57e2d..b58ec28b3d0 100644 --- a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_multiple_responses_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_multiple_responses_operations.py @@ -49,7 +49,7 @@ def get200_model204_no_model_default_error200_valid( self, **kwargs # type: Any ): - # type: (...) -> "models.MyException" + # type: (...) -> Optional["models.MyException"] """Send a 200 response with valid payload: {'statusCode': '200'}. :keyword callable cls: A custom type or function that will be passed the direct response @@ -96,7 +96,7 @@ def get200_model204_no_model_default_error204_valid( self, **kwargs # type: Any ): - # type: (...) -> "models.MyException" + # type: (...) -> Optional["models.MyException"] """Send a 204 response with no payload. :keyword callable cls: A custom type or function that will be passed the direct response @@ -143,7 +143,7 @@ def get200_model204_no_model_default_error201_invalid( self, **kwargs # type: Any ): - # type: (...) -> "models.MyException" + # type: (...) -> Optional["models.MyException"] """Send a 201 response with valid payload: {'statusCode': '201'}. :keyword callable cls: A custom type or function that will be passed the direct response @@ -190,7 +190,7 @@ def get200_model204_no_model_default_error202_none( self, **kwargs # type: Any ): - # type: (...) -> "models.MyException" + # type: (...) -> Optional["models.MyException"] """Send a 202 response with no payload:. :keyword callable cls: A custom type or function that will be passed the direct response @@ -237,7 +237,7 @@ def get200_model204_no_model_default_error400_valid( self, **kwargs # type: Any ): - # type: (...) -> "models.MyException" + # type: (...) -> Optional["models.MyException"] """Send a 400 response with valid error payload: {'status': 400, 'message': 'client error'}. :keyword callable cls: A custom type or function that will be passed the direct response diff --git a/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/aio/operations_async/_pet_operations_async.py b/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/aio/operations_async/_pet_operations_async.py index 767bc6a11d2..e043a5e40fb 100644 --- a/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/aio/operations_async/_pet_operations_async.py +++ b/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/aio/operations_async/_pet_operations_async.py @@ -45,7 +45,7 @@ async def get_pet_by_id( self, pet_id: str, **kwargs - ) -> "models.Pet": + ) -> Optional["models.Pet"]: """Gets pets by id. :param pet_id: pet id. diff --git a/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/operations/_pet_operations.py b/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/operations/_pet_operations.py index ce67512cef4..9d8e8b69552 100644 --- a/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/operations/_pet_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/operations/_pet_operations.py @@ -50,7 +50,7 @@ def get_pet_by_id( pet_id, # type: str **kwargs # type: Any ): - # type: (...) -> "models.Pet" + # type: (...) -> Optional["models.Pet"] """Gets pets by id. :param pet_id: pet id. From bef37bdf0ba1def6b1b4911e7de45f13aadb0a79 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 21 May 2020 18:55:11 -0400 Subject: [PATCH 2/8] only set deserialized = None when there's an optional return type --- autorest/codegen/templates/operation.py.jinja2 | 4 +++- .../_lr_os_custom_header_operations_async.py | 1 - .../aio/operations_async/_lro_retrys_operations_async.py | 2 -- .../Lro/lro/aio/operations_async/_lros_operations_async.py | 6 ------ .../lro/aio/operations_async/_lrosads_operations_async.py | 4 ---- .../Lro/lro/operations/_lr_os_custom_header_operations.py | 1 - .../Lro/lro/operations/_lro_retrys_operations.py | 2 -- .../AcceptanceTests/Lro/lro/operations/_lros_operations.py | 6 ------ .../Lro/lro/operations/_lrosads_operations.py | 4 ---- .../_multiple_responses_operations_async.py | 7 ------- .../operations/_multiple_responses_operations.py | 7 ------- 11 files changed, 3 insertions(+), 41 deletions(-) diff --git a/autorest/codegen/templates/operation.py.jinja2 b/autorest/codegen/templates/operation.py.jinja2 index da946a894f5..e120fd0aa44 100644 --- a/autorest/codegen/templates/operation.py.jinja2 +++ b/autorest/codegen/templates/operation.py.jinja2 @@ -62,7 +62,9 @@ {% if operation.any_response_has_headers %} response_headers = {} {% endif %} -{% if operation.has_response_body and operation.responses|count > 1 %} +{# now we only initialize deserialized to None if we know there is both > 1 response with body and > 1 response of None #} +{# otherwise, we know that deserialized will be set to a value then returned #} +{% if operation.has_optional_return_type %} deserialized = None {% endif %} {% if operation.has_response_body or operation.any_response_has_headers %} diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lr_os_custom_header_operations_async.py b/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lr_os_custom_header_operations_async.py index 207673b826b..81f4384b62f 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lr_os_custom_header_operations_async.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lr_os_custom_header_operations_async.py @@ -184,7 +184,6 @@ async def _put201_creating_succeeded200_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lro_retrys_operations_async.py b/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lro_retrys_operations_async.py index 99df448af14..bd77cc0ca9f 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lro_retrys_operations_async.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lro_retrys_operations_async.py @@ -80,7 +80,6 @@ async def _put201_creating_succeeded200_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -273,7 +272,6 @@ async def _delete_provisioning202_accepted200_succeeded_initial( raise HttpResponseError(response=response, error_format=ARMErrorFormat) response_headers = {} - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lros_operations_async.py b/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lros_operations_async.py index ff5e271b8e9..9be92ffb14c 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lros_operations_async.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lros_operations_async.py @@ -541,7 +541,6 @@ async def _put201_creating_succeeded200_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -734,7 +733,6 @@ async def _put201_creating_failed200_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -1895,7 +1893,6 @@ async def _delete_provisioning202_accepted200_succeeded_initial( raise HttpResponseError(response=response, error_format=ARMErrorFormat) response_headers = {} - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -1987,7 +1984,6 @@ async def _delete_provisioning202_deleting_failed200_initial( raise HttpResponseError(response=response, error_format=ARMErrorFormat) response_headers = {} - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -2079,7 +2075,6 @@ async def _delete_provisioning202_deletingcanceled200_initial( raise HttpResponseError(response=response, error_format=ARMErrorFormat) response_headers = {} - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -2873,7 +2868,6 @@ async def _post200_with_payload_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Sku', pipeline_response) diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lrosads_operations_async.py b/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lrosads_operations_async.py index 2dd22d05db2..c7ed1afc527 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lrosads_operations_async.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lrosads_operations_async.py @@ -80,7 +80,6 @@ async def _put_non_retry400_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -177,7 +176,6 @@ async def _put_non_retry201_creating400_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -275,7 +273,6 @@ async def _put_non_retry201_creating400_invalid_json_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -971,7 +968,6 @@ async def _put_error201_no_provisioning_state_payload_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lr_os_custom_header_operations.py b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lr_os_custom_header_operations.py index d56f08c6720..9ad5c4153e4 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lr_os_custom_header_operations.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lr_os_custom_header_operations.py @@ -191,7 +191,6 @@ def _put201_creating_succeeded200_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lro_retrys_operations.py b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lro_retrys_operations.py index 0293a8419d9..1f8dca11f95 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lro_retrys_operations.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lro_retrys_operations.py @@ -85,7 +85,6 @@ def _put201_creating_succeeded200_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -282,7 +281,6 @@ def _delete_provisioning202_accepted200_succeeded_initial( raise HttpResponseError(response=response, error_format=ARMErrorFormat) response_headers = {} - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lros_operations.py b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lros_operations.py index 999d9ab7230..dfb7479886d 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lros_operations.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lros_operations.py @@ -556,7 +556,6 @@ def _put201_creating_succeeded200_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -753,7 +752,6 @@ def _put201_creating_failed200_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -1938,7 +1936,6 @@ def _delete_provisioning202_accepted200_succeeded_initial( raise HttpResponseError(response=response, error_format=ARMErrorFormat) response_headers = {} - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -2032,7 +2029,6 @@ def _delete_provisioning202_deleting_failed200_initial( raise HttpResponseError(response=response, error_format=ARMErrorFormat) response_headers = {} - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -2126,7 +2122,6 @@ def _delete_provisioning202_deletingcanceled200_initial( raise HttpResponseError(response=response, error_format=ARMErrorFormat) response_headers = {} - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -2940,7 +2935,6 @@ def _post200_with_payload_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Sku', pipeline_response) diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lrosads_operations.py b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lrosads_operations.py index 9c70c3b1404..dba4139a859 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lrosads_operations.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lrosads_operations.py @@ -85,7 +85,6 @@ def _put_non_retry400_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -184,7 +183,6 @@ def _put_non_retry201_creating400_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -284,7 +282,6 @@ def _put_non_retry201_creating400_invalid_json_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) @@ -996,7 +993,6 @@ def _put_error201_no_provisioning_state_payload_initial( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('Product', pipeline_response) diff --git a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_multiple_responses_operations_async.py b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_multiple_responses_operations_async.py index e48e4ae855e..886abb0f5e9 100644 --- a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_multiple_responses_operations_async.py +++ b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_multiple_responses_operations_async.py @@ -306,7 +306,6 @@ async def get200_model201_model_default_error200_valid( error = self._deserialize(models.Error, response) raise HttpResponseError(response=response, model=error) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('MyException', pipeline_response) @@ -355,7 +354,6 @@ async def get200_model201_model_default_error201_valid( error = self._deserialize(models.Error, response) raise HttpResponseError(response=response, model=error) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('MyException', pipeline_response) @@ -404,7 +402,6 @@ async def get200_model201_model_default_error400_valid( error = self._deserialize(models.Error, response) raise HttpResponseError(response=response, model=error) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('MyException', pipeline_response) @@ -453,7 +450,6 @@ async def get200_model_a201_model_c404_model_d_default_error200_valid( error = self._deserialize(models.Error, response) raise HttpResponseError(response=response, model=error) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('MyException', pipeline_response) @@ -505,7 +501,6 @@ async def get200_model_a201_model_c404_model_d_default_error201_valid( error = self._deserialize(models.Error, response) raise HttpResponseError(response=response, model=error) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('MyException', pipeline_response) @@ -557,7 +552,6 @@ async def get200_model_a201_model_c404_model_d_default_error404_valid( error = self._deserialize(models.Error, response) raise HttpResponseError(response=response, model=error) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('MyException', pipeline_response) @@ -609,7 +603,6 @@ async def get200_model_a201_model_c404_model_d_default_error400_valid( error = self._deserialize(models.Error, response) raise HttpResponseError(response=response, model=error) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('MyException', pipeline_response) diff --git a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_multiple_responses_operations.py b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_multiple_responses_operations.py index b58ec28b3d0..ebe832138ac 100644 --- a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_multiple_responses_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_multiple_responses_operations.py @@ -316,7 +316,6 @@ def get200_model201_model_default_error200_valid( error = self._deserialize(models.Error, response) raise HttpResponseError(response=response, model=error) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('MyException', pipeline_response) @@ -366,7 +365,6 @@ def get200_model201_model_default_error201_valid( error = self._deserialize(models.Error, response) raise HttpResponseError(response=response, model=error) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('MyException', pipeline_response) @@ -416,7 +414,6 @@ def get200_model201_model_default_error400_valid( error = self._deserialize(models.Error, response) raise HttpResponseError(response=response, model=error) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('MyException', pipeline_response) @@ -466,7 +463,6 @@ def get200_model_a201_model_c404_model_d_default_error200_valid( error = self._deserialize(models.Error, response) raise HttpResponseError(response=response, model=error) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('MyException', pipeline_response) @@ -519,7 +515,6 @@ def get200_model_a201_model_c404_model_d_default_error201_valid( error = self._deserialize(models.Error, response) raise HttpResponseError(response=response, model=error) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('MyException', pipeline_response) @@ -572,7 +567,6 @@ def get200_model_a201_model_c404_model_d_default_error404_valid( error = self._deserialize(models.Error, response) raise HttpResponseError(response=response, model=error) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('MyException', pipeline_response) @@ -625,7 +619,6 @@ def get200_model_a201_model_c404_model_d_default_error400_valid( error = self._deserialize(models.Error, response) raise HttpResponseError(response=response, model=error) - deserialized = None if response.status_code == 200: deserialized = self._deserialize('MyException', pipeline_response) From e7600587510a4f8da38c9912a5491445398a7b8c Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 28 May 2020 11:44:26 -0400 Subject: [PATCH 3/8] regenerated with ClsType typing including the optional return typee --- autorest/codegen/models/lro_operation.py | 5 + autorest/codegen/models/paging_operation.py | 5 + .../codegen/templates/lro_operation.py.jinja2 | 3 +- .../codegen/templates/operation_tools.jinja2 | 6 +- .../_lros_operations_async.py | 36 +++--- .../_lrosads_operations_async.py | 6 +- .../_lr_os_custom_header_operations.py | 8 +- .../lro/operations/_lro_retrys_operations.py | 14 +-- .../Lro/lro/operations/_lros_operations.py | 106 +++++++++--------- .../Lro/lro/operations/_lrosads_operations.py | 56 ++++----- .../_paging_operations_async.py | 59 ++++++++++ .../Paging/paging/models/__init__.py | 3 + .../Paging/paging/models/_models.py | 23 ++++ .../Paging/paging/models/_models_py3.py | 26 +++++ .../paging/operations/_paging_operations.py | 62 +++++++++- .../_storage_accounts_operations_async.py | 6 +- .../_storage_accounts_operations.py | 6 +- .../Multiapi/multiapi/_operations_mixin.py | 2 +- .../multiapi/aio/_operations_mixin_async.py | 4 +- .../Multiapi/multiapi/v1/_metadata.json | 4 +- ...ultiapi_service_client_operations_async.py | 6 +- .../_multiapi_service_client_operations.py | 6 +- .../multiapinoasync/_operations_mixin.py | 2 +- .../multiapinoasync/v1/_metadata.json | 4 +- .../_multiapi_service_client_operations.py | 6 +- .../submodule/_operations_mixin.py | 2 +- .../submodule/aio/_operations_mixin_async.py | 4 +- .../submodule/v1/_metadata.json | 4 +- ...ultiapi_service_client_operations_async.py | 6 +- .../_multiapi_service_client_operations.py | 6 +- .../_http_redirects_operations_async.py | 2 +- .../_multiple_responses_operations_async.py | 10 +- .../operations/_http_redirects_operations.py | 2 +- .../_multiple_responses_operations.py | 10 +- .../operations_async/_pet_operations_async.py | 2 +- .../operations/_pet_operations.py | 2 +- 36 files changed, 347 insertions(+), 167 deletions(-) diff --git a/autorest/codegen/models/lro_operation.py b/autorest/codegen/models/lro_operation.py index 78be623f364..8983dd40cff 100644 --- a/autorest/codegen/models/lro_operation.py +++ b/autorest/codegen/models/lro_operation.py @@ -79,6 +79,11 @@ def set_lro_response_type(self) -> None: response_type = response_types[0] self.lro_response = response_type + @property + def has_optional_return_type(self) -> bool: + """An LROOperation will never have an optional return type, we will always return LROPoller[return type]""" + return False + def imports(self, code_model, async_mode: bool) -> FileImport: file_import = super().imports(code_model, async_mode) file_import.add_from_import("typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL) diff --git a/autorest/codegen/models/paging_operation.py b/autorest/codegen/models/paging_operation.py index 75159bd0442..b64f9b2c2b2 100644 --- a/autorest/codegen/models/paging_operation.py +++ b/autorest/codegen/models/paging_operation.py @@ -93,6 +93,11 @@ def next_link_name(self) -> Optional[str]: return None return self._find_python_name(self._next_link_name, "nextLinkName") + @property + def has_optional_return_type(self) -> bool: + """A paging will never have an optional return type, we will always return ItemPaged[return type]""" + return False + def imports(self, code_model, async_mode: bool) -> FileImport: file_import = super(PagingOperation, self).imports(code_model, async_mode) diff --git a/autorest/codegen/templates/lro_operation.py.jinja2 b/autorest/codegen/templates/lro_operation.py.jinja2 index 3d3a9a4fdaf..80959e331e1 100644 --- a/autorest/codegen/templates/lro_operation.py.jinja2 +++ b/autorest/codegen/templates/lro_operation.py.jinja2 @@ -23,8 +23,7 @@ response_headers = { {% set return_type_wrapper = "" if async_mode else "LROPoller" %} {{ op_tools.method_signature(operation, operation_name, async_mode=async_mode, coroutine=async_mode, return_type_wrapper=return_type_wrapper) }} {%- if not async_mode %} -{# overriding sync_return_type_annotation because we know if it's sync, it's return type is just LROPoller #} - # type: (...) -> LROPoller + {{ op_tools.sync_return_type_annotation(operation, return_type_wrapper) }} {% endif %} """{{ operation.summary if operation.summary else operation.description | wordwrap(width=95, break_long_words=False, wrapstring='\n') }} {% if operation.summary and operation.description %} diff --git a/autorest/codegen/templates/operation_tools.jinja2 b/autorest/codegen/templates/operation_tools.jinja2 index 11912e8c9bf..ee97255cf5c 100644 --- a/autorest/codegen/templates/operation_tools.jinja2 +++ b/autorest/codegen/templates/operation_tools.jinja2 @@ -37,11 +37,11 @@ :raises: ~azure.core.exceptions.HttpResponseError """{% endmacro %} {% macro return_type_annotation(operation, return_type_wrapper) %} -{{ ("Optional[" if operation.has_optional_return_type and not return_type_wrapper else "" ) ~ ((return_type_wrapper + "[") if return_type_wrapper else "") ~ ("Union[" if operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation') | unique | list | length > 1 else "") ~ +{{ ((return_type_wrapper + "[") if return_type_wrapper else "") ~ ("Optional[" if operation.has_optional_return_type else "" ) ~ ("Union[" if operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation') | unique | list | length > 1 else "") ~ (operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation') | unique | join(', ')) ~ -("]" if operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation')| unique | list | length > 1 else "") ~ ( "]" if return_type_wrapper else "") ~ ("]" if operation.has_optional_return_type and not return_type_wrapper else "") +("]" if operation.responses | selectattr('has_body') | map(attribute='schema') | map(attribute='operation_type_annotation')| unique | list | length > 1 else "") ~ ("]" if operation.has_optional_return_type else "") ~ ( "]" if return_type_wrapper else "") if operation.responses | selectattr('has_body') | first -else ("Optional[" if operation.has_optional_return_type and not return_type_wrapper else "" ) ~ ((return_type_wrapper + "[") if return_type_wrapper else "") ~ "None" ~ ( "]" if return_type_wrapper else "") ~ ("]" if operation.has_optional_return_type and not return_type_wrapper else "") }}{% endmacro %} +else ((return_type_wrapper + "[") if return_type_wrapper else "") ~ ("Optional[" if operation.has_optional_return_type else "" ) ~ "None" ~ ("]" if operation.has_optional_return_type else "") ~ ( "]" if return_type_wrapper else "") }}{% endmacro %} {# get async mypy typing #} {% macro async_return_type_annotation(operation, return_type_wrapper) %} {{ " -> " + return_type_annotation(operation, return_type_wrapper) }}{% endmacro %} diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lros_operations_async.py b/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lros_operations_async.py index 9be92ffb14c..f6dba33dd72 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lros_operations_async.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lros_operations_async.py @@ -48,7 +48,7 @@ async def _put200_succeeded_initial( product: Optional["models.Product"] = None, **kwargs ) -> Optional["models.Product"]: - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) content_type = kwargs.pop("content_type", "application/json") @@ -95,7 +95,7 @@ async def put200_succeeded( self, product: Optional["models.Product"] = None, **kwargs - ) -> Optional["models.Product"]: + ) -> "models.Product": """Long running put request, service returns a 200 to the initial request, with an entity that contains ProvisioningState=’Succeeded’. @@ -111,7 +111,7 @@ async def put200_succeeded( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -235,7 +235,7 @@ async def _post202_list_initial( self, **kwargs ) -> Optional[List["models.Product"]]: - cls = kwargs.pop('cls', None) # type: ClsType[List["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType[Optional[List["models.Product"]]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -277,7 +277,7 @@ async def _post202_list_initial( async def post202_list( self, **kwargs - ) -> Optional[List["models.Product"]]: + ) -> List["models.Product"]: """Long running put request, service returns a 202 with empty body to first request, returns a 200 with body [{ 'id': '100', 'name': 'foo' }]. @@ -291,7 +291,7 @@ async def post202_list( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[List["models.Product"]]] + cls = kwargs.pop('cls', None) # type: ClsType[List["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -2213,7 +2213,7 @@ async def _delete202_retry200_initial( self, **kwargs ) -> Optional["models.Product"]: - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -2255,7 +2255,7 @@ async def _delete202_retry200_initial( async def delete202_retry200( self, **kwargs - ) -> Optional["models.Product"]: + ) -> "models.Product": """Long running delete request, service returns a 202 to the initial request. Polls return this value until the last poll returns a ‘200’ with ProvisioningState=’Succeeded’. @@ -2269,7 +2269,7 @@ async def delete202_retry200( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -2299,7 +2299,7 @@ async def _delete202_no_retry204_initial( self, **kwargs ) -> Optional["models.Product"]: - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -2341,7 +2341,7 @@ async def _delete202_no_retry204_initial( async def delete202_no_retry204( self, **kwargs - ) -> Optional["models.Product"]: + ) -> "models.Product": """Long running delete request, service returns a 202 to the initial request. Polls return this value until the last poll returns a ‘200’ with ProvisioningState=’Succeeded’. @@ -2355,7 +2355,7 @@ async def delete202_no_retry204( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -3359,7 +3359,7 @@ async def _post_async_retry_succeeded_initial( product: Optional["models.Product"] = None, **kwargs ) -> Optional["models.Product"]: - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) content_type = kwargs.pop("content_type", "application/json") @@ -3412,7 +3412,7 @@ async def post_async_retry_succeeded( self, product: Optional["models.Product"] = None, **kwargs - ) -> Optional["models.Product"]: + ) -> "models.Product": """Long running post request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -3429,7 +3429,7 @@ async def post_async_retry_succeeded( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -3461,7 +3461,7 @@ async def _post_async_no_retry_succeeded_initial( product: Optional["models.Product"] = None, **kwargs ) -> Optional["models.Product"]: - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) content_type = kwargs.pop("content_type", "application/json") @@ -3514,7 +3514,7 @@ async def post_async_no_retry_succeeded( self, product: Optional["models.Product"] = None, **kwargs - ) -> Optional["models.Product"]: + ) -> "models.Product": """Long running post request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -3531,7 +3531,7 @@ async def post_async_no_retry_succeeded( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lrosads_operations_async.py b/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lrosads_operations_async.py index c7ed1afc527..def8d856e50 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lrosads_operations_async.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/aio/operations_async/_lrosads_operations_async.py @@ -1568,7 +1568,7 @@ async def _put200_invalid_json_initial( product: Optional["models.Product"] = None, **kwargs ) -> Optional["models.Product"]: - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) content_type = kwargs.pop("content_type", "application/json") @@ -1615,7 +1615,7 @@ async def put200_invalid_json( self, product: Optional["models.Product"] = None, **kwargs - ) -> Optional["models.Product"]: + ) -> "models.Product": """Long running put request, service returns a 200 to the initial request, with an entity that is not a valid json. @@ -1631,7 +1631,7 @@ async def put200_invalid_json( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lr_os_custom_header_operations.py b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lr_os_custom_header_operations.py index 9ad5c4153e4..67b75b212b5 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lr_os_custom_header_operations.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lr_os_custom_header_operations.py @@ -103,7 +103,7 @@ def begin_put_async_retry_succeeded( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """x-ms-client-request-id = 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0 is required message header for all requests. Long running put request, service returns a 200 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure- @@ -209,7 +209,7 @@ def begin_put201_creating_succeeded200( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """x-ms-client-request-id = 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0 is required message header for all requests. Long running put request, service returns a 201 to the initial request, with an entity that contains ProvisioningState=’Creating’. Polls return this value until the last poll @@ -306,7 +306,7 @@ def begin_post202_retry200( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """x-ms-client-request-id = 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0 is required message header for all requests. Long running post request, service returns a 202 to the initial request, with 'Location' and 'Retry-After' headers, Polls return a 200 with a response body after success. @@ -400,7 +400,7 @@ def begin_post_async_retry_succeeded( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """x-ms-client-request-id = 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0 is required message header for all requests. Long running post request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure- diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lro_retrys_operations.py b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lro_retrys_operations.py index 1f8dca11f95..5fd2009886f 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lro_retrys_operations.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lro_retrys_operations.py @@ -103,7 +103,7 @@ def begin_put201_creating_succeeded200( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 500, then a 201 to the initial request, with an entity that contains ProvisioningState=’Creating’. Polls return this value until the last poll returns a ‘200’ with ProvisioningState=’Succeeded’. @@ -203,7 +203,7 @@ def begin_put_async_relative_retry_succeeded( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 500, then a 200 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure- AsyncOperation header for operation status. @@ -300,7 +300,7 @@ def begin_delete_provisioning202_accepted200_succeeded( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running delete request, service returns a 500, then a 202 to the initial request, with an entity that contains ProvisioningState=’Accepted’. Polls return this value until the last poll returns a ‘200’ with ProvisioningState=’Succeeded’. @@ -386,7 +386,7 @@ def begin_delete202_retry200( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running delete request, service returns a 500, then a 202 to the initial request. Polls return this value until the last poll returns a ‘200’ with ProvisioningState=’Succeeded’. @@ -465,7 +465,7 @@ def begin_delete_async_relative_retry_succeeded( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running delete request, service returns a 500, then a 202 to the initial request. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -554,7 +554,7 @@ def begin_post202_retry200( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running post request, service returns a 500, then a 202 to the initial request, with 'Location' and 'Retry-After' headers, Polls return a 200 with a response body after success. @@ -647,7 +647,7 @@ def begin_post_async_relative_retry_succeeded( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running post request, service returns a 500, then a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure- AsyncOperation header for operation status. diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lros_operations.py b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lros_operations.py index dfb7479886d..5ec9eeb7881 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lros_operations.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lros_operations.py @@ -53,7 +53,7 @@ def _put200_succeeded_initial( **kwargs # type: Any ): # type: (...) -> Optional["models.Product"] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) content_type = kwargs.pop("content_type", "application/json") @@ -101,7 +101,7 @@ def begin_put200_succeeded( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 200 to the initial request, with an entity that contains ProvisioningState=’Succeeded’. @@ -117,7 +117,7 @@ def begin_put200_succeeded( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -196,7 +196,7 @@ def begin_put201_succeeded( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 201 to the initial request, with an entity that contains ProvisioningState=’Succeeded’. @@ -244,7 +244,7 @@ def _post202_list_initial( **kwargs # type: Any ): # type: (...) -> Optional[List["models.Product"]] - cls = kwargs.pop('cls', None) # type: ClsType[List["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType[Optional[List["models.Product"]]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -287,7 +287,7 @@ def begin_post202_list( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[List["models.Product"]] """Long running put request, service returns a 202 with empty body to first request, returns a 200 with body [{ 'id': '100', 'name': 'foo' }]. @@ -301,7 +301,7 @@ def begin_post202_list( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional[List["models.Product"]]] + cls = kwargs.pop('cls', None) # type: ClsType[List["models.Product"]] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -379,7 +379,7 @@ def begin_put200_succeeded_no_state( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 200 to the initial request, with an entity that does not contain ProvisioningState=’Succeeded’. @@ -474,7 +474,7 @@ def begin_put202_retry200( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 202 to the initial request, with a location header that points to a polling URL that returns a 200 and an entity that doesn't contains ProvisioningState. @@ -574,7 +574,7 @@ def begin_put201_creating_succeeded200( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 201 to the initial request, with an entity that contains ProvisioningState=’Creating’. Polls return this value until the last poll returns a ‘200’ with ProvisioningState=’Succeeded’. @@ -670,7 +670,7 @@ def begin_put200_updating_succeeded204( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 201 to the initial request, with an entity that contains ProvisioningState=’Updating’. Polls return this value until the last poll returns a ‘200’ with ProvisioningState=’Succeeded’. @@ -770,7 +770,7 @@ def begin_put201_creating_failed200( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 201 to the initial request, with an entity that contains ProvisioningState=’Created’. Polls return this value until the last poll returns a ‘200’ with ProvisioningState=’Failed’. @@ -866,7 +866,7 @@ def begin_put200_acceptedcanceled200( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 201 to the initial request, with an entity that contains ProvisioningState=’Creating’. Polls return this value until the last poll returns a ‘200’ with ProvisioningState=’Canceled’. @@ -964,7 +964,7 @@ def begin_put_no_header_in_retry( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 202 to the initial request with location header. Subsequent calls to operation status do not contain location header. @@ -1066,7 +1066,7 @@ def begin_put_async_retry_succeeded( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 200 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -1170,7 +1170,7 @@ def begin_put_async_no_retry_succeeded( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 200 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -1274,7 +1274,7 @@ def begin_put_async_retry_failed( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 200 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -1378,7 +1378,7 @@ def begin_put_async_no_retrycanceled( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 200 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -1480,7 +1480,7 @@ def begin_put_async_no_header_in_retry( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 202 to the initial request with Azure- AsyncOperation header. Subsequent calls to operation status do not contain Azure-AsyncOperation header. @@ -1579,7 +1579,7 @@ def begin_put_non_resource( sku=None, # type: Optional["models.Sku"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Sku"] """Long running put request with non resource. :param sku: sku to put. @@ -1673,7 +1673,7 @@ def begin_put_async_non_resource( sku=None, # type: Optional["models.Sku"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Sku"] """Long running put request with non resource. :param sku: Sku to put. @@ -1769,7 +1769,7 @@ def begin_put_sub_resource( provisioning_state=None, # type: Optional[str] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.SubProduct"] """Long running put request with sub resource. :param provisioning_state: @@ -1865,7 +1865,7 @@ def begin_put_async_sub_resource( provisioning_state=None, # type: Optional[str] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.SubProduct"] """Long running put request with sub resource. :param provisioning_state: @@ -1955,7 +1955,7 @@ def begin_delete_provisioning202_accepted200_succeeded( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running delete request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Accepted’. Polls return this value until the last poll returns a ‘200’ with ProvisioningState=’Succeeded’. @@ -2048,7 +2048,7 @@ def begin_delete_provisioning202_deleting_failed200( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running delete request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. Polls return this value until the last poll returns a ‘200’ with ProvisioningState=’Failed’. @@ -2141,7 +2141,7 @@ def begin_delete_provisioning202_deletingcanceled200( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running delete request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. Polls return this value until the last poll returns a ‘200’ with ProvisioningState=’Canceled’. @@ -2223,7 +2223,7 @@ def begin_delete204_succeeded( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running delete succeeds and returns right away. :keyword callable cls: A custom type or function that will be passed the direct response @@ -2264,7 +2264,7 @@ def _delete202_retry200_initial( **kwargs # type: Any ): # type: (...) -> Optional["models.Product"] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -2307,7 +2307,7 @@ def begin_delete202_retry200( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running delete request, service returns a 202 to the initial request. Polls return this value until the last poll returns a ‘200’ with ProvisioningState=’Succeeded’. @@ -2321,7 +2321,7 @@ def begin_delete202_retry200( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -2352,7 +2352,7 @@ def _delete202_no_retry204_initial( **kwargs # type: Any ): # type: (...) -> Optional["models.Product"] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -2395,7 +2395,7 @@ def begin_delete202_no_retry204( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running delete request, service returns a 202 to the initial request. Polls return this value until the last poll returns a ‘200’ with ProvisioningState=’Succeeded’. @@ -2409,7 +2409,7 @@ def begin_delete202_no_retry204( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -2476,7 +2476,7 @@ def begin_delete_no_header_in_retry( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running delete request, service returns a location header in the initial request. Subsequent calls to operation status do not contain location header. @@ -2554,7 +2554,7 @@ def begin_delete_async_no_header_in_retry( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running delete request, service returns an Azure-AsyncOperation header in the initial request. Subsequent calls to operation status do not contain Azure-AsyncOperation header. @@ -2633,7 +2633,7 @@ def begin_delete_async_retry_succeeded( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running delete request, service returns a 202 to the initial request. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -2712,7 +2712,7 @@ def begin_delete_async_no_retry_succeeded( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running delete request, service returns a 202 to the initial request. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -2791,7 +2791,7 @@ def begin_delete_async_retry_failed( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running delete request, service returns a 202 to the initial request. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -2870,7 +2870,7 @@ def begin_delete_async_retrycanceled( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running delete request, service returns a 202 to the initial request. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -2952,7 +2952,7 @@ def begin_post200_with_payload( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Sku"] """Long running post request, service returns a 202 to the initial request, with 'Location' header. Poll returns a 200 with a response body after success. @@ -3044,7 +3044,7 @@ def begin_post202_retry200( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running post request, service returns a 202 to the initial request, with 'Location' and 'Retry-After' headers, Polls return a 200 with a response body after success. @@ -3139,7 +3139,7 @@ def begin_post202_no_retry204( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running post request, service returns a 202 to the initial request, with 'Location' header, 204 with noresponse body after success. @@ -3227,7 +3227,7 @@ def begin_post_double_headers_final_location_get( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running post request, service returns a 202 to the initial request with both Location and Azure-Async header. Poll Azure-Async and it's success. Should poll Location to get the final object. @@ -3309,7 +3309,7 @@ def begin_post_double_headers_final_azure_header_get( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running post request, service returns a 202 to the initial request with both Location and Azure-Async header. Poll Azure-Async and it's success. Should NOT poll Location to get the final object. @@ -3391,7 +3391,7 @@ def begin_post_double_headers_final_azure_header_get_default( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running post request, service returns a 202 to the initial request with both Location and Azure-Async header. Poll Azure-Async and it's success. Should NOT poll Location to get the final object if you support initial Autorest behavior. @@ -3438,7 +3438,7 @@ def _post_async_retry_succeeded_initial( **kwargs # type: Any ): # type: (...) -> Optional["models.Product"] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) content_type = kwargs.pop("content_type", "application/json") @@ -3492,7 +3492,7 @@ def begin_post_async_retry_succeeded( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running post request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -3509,7 +3509,7 @@ def begin_post_async_retry_succeeded( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -3542,7 +3542,7 @@ def _post_async_no_retry_succeeded_initial( **kwargs # type: Any ): # type: (...) -> Optional["models.Product"] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) content_type = kwargs.pop("content_type", "application/json") @@ -3596,7 +3596,7 @@ def begin_post_async_no_retry_succeeded( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running post request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -3613,7 +3613,7 @@ def begin_post_async_no_retry_succeeded( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -3693,7 +3693,7 @@ def begin_post_async_retry_failed( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running post request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -3787,7 +3787,7 @@ def begin_post_async_retrycanceled( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running post request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. diff --git a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lrosads_operations.py b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lrosads_operations.py index dba4139a859..39068234a8e 100644 --- a/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lrosads_operations.py +++ b/test/azure/Expected/AcceptanceTests/Lro/lro/operations/_lrosads_operations.py @@ -103,7 +103,7 @@ def begin_put_non_retry400( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 400 to the initial request. :param product: Product to put. @@ -201,7 +201,7 @@ def begin_put_non_retry201_creating400( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a Product with 'ProvisioningState' = 'Creating' and 201 response code. @@ -300,7 +300,7 @@ def begin_put_non_retry201_creating400_invalid_json( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a Product with 'ProvisioningState' = 'Creating' and 201 response code. @@ -399,7 +399,7 @@ def begin_put_async_relative_retry400( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 200 with ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -488,7 +488,7 @@ def begin_delete_non_retry400( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running delete request, service returns a 400 with an error body. :keyword callable cls: A custom type or function that will be passed the direct response @@ -565,7 +565,7 @@ def begin_delete202_non_retry400( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running delete request, service returns a 202 with a location header. :keyword callable cls: A custom type or function that will be passed the direct response @@ -643,7 +643,7 @@ def begin_delete_async_relative_retry400( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running delete request, service returns a 202 to the initial request. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -732,7 +732,7 @@ def begin_post_non_retry400( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running post request, service returns a 400 with no error body. :param product: Product to put. @@ -823,7 +823,7 @@ def begin_post202_non_retry400( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running post request, service returns a 202 with a location header. :param product: Product to put. @@ -915,7 +915,7 @@ def begin_post_async_relative_retry400( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running post request, service returns a 202 to the initial request Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -1011,7 +1011,7 @@ def begin_put_error201_no_provisioning_state_payload( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 201 to the initial request with no payload. :param product: Product to put. @@ -1109,7 +1109,7 @@ def begin_put_async_relative_retry_no_status( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 200 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -1214,7 +1214,7 @@ def begin_put_async_relative_retry_no_status_payload( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 200 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -1300,7 +1300,7 @@ def begin_delete204_succeeded( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running delete request, service returns a 204 to the initial request, indicating success. :keyword callable cls: A custom type or function that will be passed the direct response @@ -1378,7 +1378,7 @@ def begin_delete_async_relative_retry_no_status( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running delete request, service returns a 202 to the initial request. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -1467,7 +1467,7 @@ def begin_post202_no_location( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running post request, service returns a 202 to the initial request, without a location header. @@ -1560,7 +1560,7 @@ def begin_post_async_relative_retry_no_payload( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running post request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -1607,7 +1607,7 @@ def _put200_invalid_json_initial( **kwargs # type: Any ): # type: (...) -> Optional["models.Product"] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) content_type = kwargs.pop("content_type", "application/json") @@ -1655,7 +1655,7 @@ def begin_put200_invalid_json( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 200 to the initial request, with an entity that is not a valid json. @@ -1671,7 +1671,7 @@ def begin_put200_invalid_json( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval @@ -1754,7 +1754,7 @@ def begin_put_async_relative_retry_invalid_header( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 200 to the initial request, with an entity that contains ProvisioningState=’Creating’. The endpoint indicated in the Azure-AsyncOperation header is invalid. @@ -1859,7 +1859,7 @@ def begin_put_async_relative_retry_invalid_json_polling( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Long running put request, service returns a 200 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -1949,7 +1949,7 @@ def begin_delete202_retry_invalid_header( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running delete request, service returns a 202 to the initial request receing a reponse with an invalid 'Location' and 'Retry-After' headers. @@ -2028,7 +2028,7 @@ def begin_delete_async_relative_retry_invalid_header( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running delete request, service returns a 202 to the initial request. The endpoint indicated in the Azure-AsyncOperation header is invalid. @@ -2107,7 +2107,7 @@ def begin_delete_async_relative_retry_invalid_json_polling( self, **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running delete request, service returns a 202 to the initial request. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. @@ -2196,7 +2196,7 @@ def begin_post202_retry_invalid_header( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running post request, service returns a 202 to the initial request, with invalid 'Location' and 'Retry-After' headers. @@ -2289,7 +2289,7 @@ def begin_post_async_relative_retry_invalid_header( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running post request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. The endpoint indicated in the Azure-AsyncOperation header is invalid. @@ -2383,7 +2383,7 @@ def begin_post_async_relative_retry_invalid_json_polling( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller[None] """Long running post request, service returns a 202 to the initial request, with an entity that contains ProvisioningState=’Creating’. Poll the endpoint indicated in the Azure-AsyncOperation header for operation status. diff --git a/test/azure/Expected/AcceptanceTests/Paging/paging/aio/operations_async/_paging_operations_async.py b/test/azure/Expected/AcceptanceTests/Paging/paging/aio/operations_async/_paging_operations_async.py index 6c969876e16..c37af9831ca 100644 --- a/test/azure/Expected/AcceptanceTests/Paging/paging/aio/operations_async/_paging_operations_async.py +++ b/test/azure/Expected/AcceptanceTests/Paging/paging/aio/operations_async/_paging_operations_async.py @@ -1070,3 +1070,62 @@ def get_long_running_output(pipeline_response): else: polling_method = polling return await async_poller(self._client, raw_result, get_long_running_output, polling_method) get_multiple_pages_lro.metadata = {'url': '/paging/multiple/lro'} # type: ignore + + @distributed_trace + def get_paging_model_with_item_name_with_xms_client_name( + self, + **kwargs + ) -> AsyncIterable["models.ProductResultValueWithXMSClientName"]: + """A paging operation that returns a paging model whose item name is is overriden by x-ms-client- + name 'indexes'. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ProductResultValueWithXMSClientName or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~paging.models.ProductResultValueWithXMSClientName] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.ProductResultValueWithXMSClientName"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + def prepare_request(next_link=None): + if not next_link: + # Construct URL + url = self.get_paging_model_with_item_name_with_xms_client_name.metadata['url'] # type: ignore + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = 'application/json' + + # Construct and send request + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('ProductResultValueWithXMSClientName', pipeline_response) + list_of_elem = deserialized.indexes + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + get_paging_model_with_item_name_with_xms_client_name.metadata = {'url': '/paging/itemNameWithXMSClientName'} # type: ignore diff --git a/test/azure/Expected/AcceptanceTests/Paging/paging/models/__init__.py b/test/azure/Expected/AcceptanceTests/Paging/paging/models/__init__.py index 7b47cf9c471..865518351bf 100644 --- a/test/azure/Expected/AcceptanceTests/Paging/paging/models/__init__.py +++ b/test/azure/Expected/AcceptanceTests/Paging/paging/models/__init__.py @@ -18,6 +18,7 @@ from ._models_py3 import ProductProperties from ._models_py3 import ProductResult from ._models_py3 import ProductResultValue + from ._models_py3 import ProductResultValueWithXMSClientName except (SyntaxError, ImportError): from ._models import CustomParameterGroup # type: ignore from ._models import OdataProductResult # type: ignore @@ -30,6 +31,7 @@ from ._models import ProductProperties # type: ignore from ._models import ProductResult # type: ignore from ._models import ProductResultValue # type: ignore + from ._models import ProductResultValueWithXMSClientName # type: ignore from ._auto_rest_paging_test_service_enums import ( OperationResultStatus, @@ -47,5 +49,6 @@ 'ProductProperties', 'ProductResult', 'ProductResultValue', + 'ProductResultValueWithXMSClientName', 'OperationResultStatus', ] diff --git a/test/azure/Expected/AcceptanceTests/Paging/paging/models/_models.py b/test/azure/Expected/AcceptanceTests/Paging/paging/models/_models.py index 9f3232171bb..34d9c17d658 100644 --- a/test/azure/Expected/AcceptanceTests/Paging/paging/models/_models.py +++ b/test/azure/Expected/AcceptanceTests/Paging/paging/models/_models.py @@ -275,3 +275,26 @@ def __init__( super(ProductResultValue, self).__init__(**kwargs) self.value = kwargs.get('value', None) self.next_link = kwargs.get('next_link', None) + + +class ProductResultValueWithXMSClientName(msrest.serialization.Model): + """ProductResultValueWithXMSClientName. + + :param indexes: + :type indexes: list[~paging.models.Product] + :param next_link: + :type next_link: str + """ + + _attribute_map = { + 'indexes': {'key': 'values', 'type': '[Product]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(ProductResultValueWithXMSClientName, self).__init__(**kwargs) + self.indexes = kwargs.get('indexes', None) + self.next_link = kwargs.get('next_link', None) diff --git a/test/azure/Expected/AcceptanceTests/Paging/paging/models/_models_py3.py b/test/azure/Expected/AcceptanceTests/Paging/paging/models/_models_py3.py index 8bffe0e249f..54edeb96bc6 100644 --- a/test/azure/Expected/AcceptanceTests/Paging/paging/models/_models_py3.py +++ b/test/azure/Expected/AcceptanceTests/Paging/paging/models/_models_py3.py @@ -311,3 +311,29 @@ def __init__( super(ProductResultValue, self).__init__(**kwargs) self.value = value self.next_link = next_link + + +class ProductResultValueWithXMSClientName(msrest.serialization.Model): + """ProductResultValueWithXMSClientName. + + :param indexes: + :type indexes: list[~paging.models.Product] + :param next_link: + :type next_link: str + """ + + _attribute_map = { + 'indexes': {'key': 'values', 'type': '[Product]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + indexes: Optional[List["Product"]] = None, + next_link: Optional[str] = None, + **kwargs + ): + super(ProductResultValueWithXMSClientName, self).__init__(**kwargs) + self.indexes = indexes + self.next_link = next_link diff --git a/test/azure/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py b/test/azure/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py index 32c705d15ab..2633402d021 100644 --- a/test/azure/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py +++ b/test/azure/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py @@ -1045,7 +1045,7 @@ def begin_get_multiple_pages_lro( paging_get_multiple_pages_lro_options=None, # type: Optional["models.PagingGetMultiplePagesLroOptions"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.ProductResult"] """A long-running paging operation that includes a nextLink that has 10 pages. :param client_request_id: @@ -1089,3 +1089,63 @@ def get_long_running_output(pipeline_response): else: polling_method = polling return LROPoller(self._client, raw_result, get_long_running_output, polling_method) begin_get_multiple_pages_lro.metadata = {'url': '/paging/multiple/lro'} # type: ignore + + @distributed_trace + def get_paging_model_with_item_name_with_xms_client_name( + self, + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.ProductResultValueWithXMSClientName"] + """A paging operation that returns a paging model whose item name is is overriden by x-ms-client- + name 'indexes'. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ProductResultValueWithXMSClientName or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~paging.models.ProductResultValueWithXMSClientName] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.ProductResultValueWithXMSClientName"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + def prepare_request(next_link=None): + if not next_link: + # Construct URL + url = self.get_paging_model_with_item_name_with_xms_client_name.metadata['url'] # type: ignore + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = 'application/json' + + # Construct and send request + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('ProductResultValueWithXMSClientName', pipeline_response) + list_of_elem = deserialized.indexes + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + get_paging_model_with_item_name_with_xms_client_name.metadata = {'url': '/paging/itemNameWithXMSClientName'} # type: ignore diff --git a/test/azure/Expected/AcceptanceTests/StorageManagementClient/storage/aio/operations_async/_storage_accounts_operations_async.py b/test/azure/Expected/AcceptanceTests/StorageManagementClient/storage/aio/operations_async/_storage_accounts_operations_async.py index 24c0caafb0e..08f3d93e286 100644 --- a/test/azure/Expected/AcceptanceTests/StorageManagementClient/storage/aio/operations_async/_storage_accounts_operations_async.py +++ b/test/azure/Expected/AcceptanceTests/StorageManagementClient/storage/aio/operations_async/_storage_accounts_operations_async.py @@ -112,7 +112,7 @@ async def _create_initial( parameters: "models.StorageAccountCreateParameters", **kwargs ) -> Optional["models.StorageAccount"]: - cls = kwargs.pop('cls', None) # type: ClsType["models.StorageAccount"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.StorageAccount"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) api_version = "2015-05-01-preview" @@ -166,7 +166,7 @@ async def create( account_name: str, parameters: "models.StorageAccountCreateParameters", **kwargs - ) -> Optional["models.StorageAccount"]: + ) -> "models.StorageAccount": """Asynchronously creates a new storage account with the specified parameters. Existing accounts cannot be updated with this API and should instead use the Update Storage Account API. If an account is already created and subsequent PUT request is issued with exact same set of @@ -190,7 +190,7 @@ async def create( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.StorageAccount"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.StorageAccount"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/azure/Expected/AcceptanceTests/StorageManagementClient/storage/operations/_storage_accounts_operations.py b/test/azure/Expected/AcceptanceTests/StorageManagementClient/storage/operations/_storage_accounts_operations.py index 12d22d6f4c3..d0fb6366e48 100644 --- a/test/azure/Expected/AcceptanceTests/StorageManagementClient/storage/operations/_storage_accounts_operations.py +++ b/test/azure/Expected/AcceptanceTests/StorageManagementClient/storage/operations/_storage_accounts_operations.py @@ -117,7 +117,7 @@ def _create_initial( **kwargs # type: Any ): # type: (...) -> Optional["models.StorageAccount"] - cls = kwargs.pop('cls', None) # type: ClsType["models.StorageAccount"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.StorageAccount"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) api_version = "2015-05-01-preview" @@ -172,7 +172,7 @@ def begin_create( parameters, # type: "models.StorageAccountCreateParameters" **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.StorageAccount"] """Asynchronously creates a new storage account with the specified parameters. Existing accounts cannot be updated with this API and should instead use the Update Storage Account API. If an account is already created and subsequent PUT request is issued with exact same set of @@ -196,7 +196,7 @@ def begin_create( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.StorageAccount"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.StorageAccount"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/_operations_mixin.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/_operations_mixin.py index e53cbcf6409..6b1c68b498a 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/_operations_mixin.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/_operations_mixin.py @@ -35,7 +35,7 @@ def begin_test_lro( :type product: ~multiapi.v1.models.Product :keyword callable cls: A custom type or function that will be passed the direct response :return: Product, or the result of cls(response) - :rtype: ~multiapi.v1.models.Product or None + :rtype: ~multiapi.v1.models.Product :raises: ~azure.core.exceptions.HttpResponseError """ api_version = self._get_api_version('begin_test_lro') diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/aio/_operations_mixin_async.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/aio/_operations_mixin_async.py index 92905d0f4ec..ff9806f0565 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/aio/_operations_mixin_async.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/aio/_operations_mixin_async.py @@ -24,14 +24,14 @@ async def test_lro( self, product: Optional["models.Product"] = None, **kwargs - ) -> Optional["models.Product"]: + ) -> "models.Product": """Put in whatever shape of Product you want, will return a Product with id equal to 100. :param product: Product to put. :type product: ~multiapi.v1.models.Product :keyword callable cls: A custom type or function that will be passed the direct response :return: Product, or the result of cls(response) - :rtype: ~multiapi.v1.models.Product or None + :rtype: ~multiapi.v1.models.Product :raises: ~azure.core.exceptions.HttpResponseError """ api_version = self._get_api_version('test_lro') diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/_metadata.json b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/_metadata.json index 40f24305206..09e2553a708 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/_metadata.json @@ -68,10 +68,10 @@ }, "async": { "operation_name": "test_lro", - "signature": "async def test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"models.Product\"]:\n", + "signature": "async def test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e \"models.Product\":\n", "coroutine": true }, - "doc": " \"\"\"Put in whatever shape of Product you want, will return a Product with id equal to 100.\n\n:param product: Product to put.\n:type product: ~multiapi.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapi.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"", + "doc": " \"\"\"Put in whatever shape of Product you want, will return a Product with id equal to 100.\n\n:param product: Product to put.\n:type product: ~multiapi.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapi.v1.models.Product\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"", "call": "product" } }, diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/aio/operations_async/_multiapi_service_client_operations_async.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/aio/operations_async/_multiapi_service_client_operations_async.py index a682ff2a578..4979a8bd9d8 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/aio/operations_async/_multiapi_service_client_operations_async.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/aio/operations_async/_multiapi_service_client_operations_async.py @@ -76,7 +76,7 @@ async def _test_lro_initial( product: Optional["models.Product"] = None, **kwargs ) -> Optional["models.Product"]: - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) content_type = kwargs.pop("content_type", "application/json") @@ -123,7 +123,7 @@ async def test_lro( self, product: Optional["models.Product"] = None, **kwargs - ) -> Optional["models.Product"]: + ) -> "models.Product": """Put in whatever shape of Product you want, will return a Product with id equal to 100. :param product: Product to put. @@ -138,7 +138,7 @@ async def test_lro( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', False) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/operations/_multiapi_service_client_operations.py index 27f120de17e..56129e5d84a 100644 --- a/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/Multiapi/multiapi/v1/operations/_multiapi_service_client_operations.py @@ -82,7 +82,7 @@ def _test_lro_initial( **kwargs # type: Any ): # type: (...) -> Optional["models.Product"] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) content_type = kwargs.pop("content_type", "application/json") @@ -130,7 +130,7 @@ def begin_test_lro( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Put in whatever shape of Product you want, will return a Product with id equal to 100. :param product: Product to put. @@ -145,7 +145,7 @@ def begin_test_lro( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', False) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/_operations_mixin.py b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/_operations_mixin.py index 389fa6cc5a1..2e42114fc77 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/_operations_mixin.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/_operations_mixin.py @@ -35,7 +35,7 @@ def begin_test_lro( :type product: ~multiapinoasync.v1.models.Product :keyword callable cls: A custom type or function that will be passed the direct response :return: Product, or the result of cls(response) - :rtype: ~multiapinoasync.v1.models.Product or None + :rtype: ~multiapinoasync.v1.models.Product :raises: ~azure.core.exceptions.HttpResponseError """ api_version = self._get_api_version('begin_test_lro') diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/_metadata.json b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/_metadata.json index f97fda8692e..f62586bc099 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/_metadata.json @@ -68,10 +68,10 @@ }, "async": { "operation_name": "test_lro", - "signature": "async def test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"models.Product\"]:\n", + "signature": "async def test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e \"models.Product\":\n", "coroutine": true }, - "doc": " \"\"\"Put in whatever shape of Product you want, will return a Product with id equal to 100.\n\n:param product: Product to put.\n:type product: ~multiapinoasync.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapinoasync.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"", + "doc": " \"\"\"Put in whatever shape of Product you want, will return a Product with id equal to 100.\n\n:param product: Product to put.\n:type product: ~multiapinoasync.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapinoasync.v1.models.Product\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"", "call": "product" } }, diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/operations/_multiapi_service_client_operations.py index 634d0d1fb91..e432423c498 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiNoAsync/multiapinoasync/v1/operations/_multiapi_service_client_operations.py @@ -82,7 +82,7 @@ def _test_lro_initial( **kwargs # type: Any ): # type: (...) -> Optional["models.Product"] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) content_type = kwargs.pop("content_type", "application/json") @@ -130,7 +130,7 @@ def begin_test_lro( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Put in whatever shape of Product you want, will return a Product with id equal to 100. :param product: Product to put. @@ -145,7 +145,7 @@ def begin_test_lro( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', False) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/_operations_mixin.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/_operations_mixin.py index 07febfed3c6..28242d4821e 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/_operations_mixin.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/_operations_mixin.py @@ -35,7 +35,7 @@ def begin_test_lro( :type product: ~multiapiwithsubmodule.submodule.v1.models.Product :keyword callable cls: A custom type or function that will be passed the direct response :return: Product, or the result of cls(response) - :rtype: ~multiapiwithsubmodule.submodule.v1.models.Product or None + :rtype: ~multiapiwithsubmodule.submodule.v1.models.Product :raises: ~azure.core.exceptions.HttpResponseError """ api_version = self._get_api_version('begin_test_lro') diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/aio/_operations_mixin_async.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/aio/_operations_mixin_async.py index 378c33d65c3..861f39616b1 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/aio/_operations_mixin_async.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/aio/_operations_mixin_async.py @@ -24,14 +24,14 @@ async def test_lro( self, product: Optional["models.Product"] = None, **kwargs - ) -> Optional["models.Product"]: + ) -> "models.Product": """Put in whatever shape of Product you want, will return a Product with id equal to 100. :param product: Product to put. :type product: ~multiapiwithsubmodule.submodule.v1.models.Product :keyword callable cls: A custom type or function that will be passed the direct response :return: Product, or the result of cls(response) - :rtype: ~multiapiwithsubmodule.submodule.v1.models.Product or None + :rtype: ~multiapiwithsubmodule.submodule.v1.models.Product :raises: ~azure.core.exceptions.HttpResponseError """ api_version = self._get_api_version('test_lro') diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/_metadata.json b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/_metadata.json index 96a6ab11dce..c9bc7978120 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/_metadata.json +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/_metadata.json @@ -68,10 +68,10 @@ }, "async": { "operation_name": "test_lro", - "signature": "async def test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"models.Product\"]:\n", + "signature": "async def test_lro(\n self,\n product: Optional[\"models.Product\"] = None,\n **kwargs\n) -\u003e \"models.Product\":\n", "coroutine": true }, - "doc": " \"\"\"Put in whatever shape of Product you want, will return a Product with id equal to 100.\n\n:param product: Product to put.\n:type product: ~multiapiwithsubmodule.submodule.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapiwithsubmodule.submodule.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"", + "doc": " \"\"\"Put in whatever shape of Product you want, will return a Product with id equal to 100.\n\n:param product: Product to put.\n:type product: ~multiapiwithsubmodule.submodule.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: Product, or the result of cls(response)\n:rtype: ~multiapiwithsubmodule.submodule.v1.models.Product\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\"", "call": "product" } }, diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/aio/operations_async/_multiapi_service_client_operations_async.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/aio/operations_async/_multiapi_service_client_operations_async.py index b963bc4303b..3c88e3c917e 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/aio/operations_async/_multiapi_service_client_operations_async.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/aio/operations_async/_multiapi_service_client_operations_async.py @@ -76,7 +76,7 @@ async def _test_lro_initial( product: Optional["models.Product"] = None, **kwargs ) -> Optional["models.Product"]: - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) content_type = kwargs.pop("content_type", "application/json") @@ -123,7 +123,7 @@ async def test_lro( self, product: Optional["models.Product"] = None, **kwargs - ) -> Optional["models.Product"]: + ) -> "models.Product": """Put in whatever shape of Product you want, will return a Product with id equal to 100. :param product: Product to put. @@ -138,7 +138,7 @@ async def test_lro( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', False) # type: Union[bool, AsyncPollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/operations/_multiapi_service_client_operations.py b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/operations/_multiapi_service_client_operations.py index 7ce6942377a..385a5e0f12c 100644 --- a/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/operations/_multiapi_service_client_operations.py +++ b/test/multiapi/Expected/AcceptanceTests/MultiapiWithSubmodule/multiapiwithsubmodule/submodule/v1/operations/_multiapi_service_client_operations.py @@ -82,7 +82,7 @@ def _test_lro_initial( **kwargs # type: Any ): # type: (...) -> Optional["models.Product"] - cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) content_type = kwargs.pop("content_type", "application/json") @@ -130,7 +130,7 @@ def begin_test_lro( product=None, # type: Optional["models.Product"] **kwargs # type: Any ): - # type: (...) -> LROPoller + # type: (...) -> LROPoller["models.Product"] """Put in whatever shape of Product you want, will return a Product with id equal to 100. :param product: Product to put. @@ -145,7 +145,7 @@ def begin_test_lro( :raises ~azure.core.exceptions.HttpResponseError: """ polling = kwargs.pop('polling', False) # type: Union[bool, PollingMethod] - cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Product"]] + cls = kwargs.pop('cls', None) # type: ClsType["models.Product"] lro_delay = kwargs.pop( 'polling_interval', self._config.polling_interval diff --git a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_http_redirects_operations_async.py b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_http_redirects_operations_async.py index 69b46c7e64f..5339cc0aef1 100644 --- a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_http_redirects_operations_async.py +++ b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_http_redirects_operations_async.py @@ -96,7 +96,7 @@ async def get300( :rtype: list[str] or None :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType[List[str]] + cls = kwargs.pop('cls', None) # type: ClsType[Optional[List[str]]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) diff --git a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_multiple_responses_operations_async.py b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_multiple_responses_operations_async.py index 886abb0f5e9..60c2fc4a5b4 100644 --- a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_multiple_responses_operations_async.py +++ b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/aio/operations_async/_multiple_responses_operations_async.py @@ -52,7 +52,7 @@ async def get200_model204_no_model_default_error200_valid( :rtype: ~httpinfrastructure.models.MyException or None :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.MyException"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.MyException"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -98,7 +98,7 @@ async def get200_model204_no_model_default_error204_valid( :rtype: ~httpinfrastructure.models.MyException or None :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.MyException"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.MyException"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -144,7 +144,7 @@ async def get200_model204_no_model_default_error201_invalid( :rtype: ~httpinfrastructure.models.MyException or None :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.MyException"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.MyException"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -190,7 +190,7 @@ async def get200_model204_no_model_default_error202_none( :rtype: ~httpinfrastructure.models.MyException or None :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.MyException"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.MyException"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -236,7 +236,7 @@ async def get200_model204_no_model_default_error400_valid( :rtype: ~httpinfrastructure.models.MyException or None :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.MyException"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.MyException"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) diff --git a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_http_redirects_operations.py b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_http_redirects_operations.py index c9b72655aa0..45af93c2e77 100644 --- a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_http_redirects_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_http_redirects_operations.py @@ -102,7 +102,7 @@ def get300( :rtype: list[str] or None :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType[List[str]] + cls = kwargs.pop('cls', None) # type: ClsType[Optional[List[str]]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) diff --git a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_multiple_responses_operations.py b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_multiple_responses_operations.py index ebe832138ac..97ea5baab15 100644 --- a/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_multiple_responses_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/Http/httpinfrastructure/operations/_multiple_responses_operations.py @@ -57,7 +57,7 @@ def get200_model204_no_model_default_error200_valid( :rtype: ~httpinfrastructure.models.MyException or None :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.MyException"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.MyException"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -104,7 +104,7 @@ def get200_model204_no_model_default_error204_valid( :rtype: ~httpinfrastructure.models.MyException or None :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.MyException"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.MyException"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -151,7 +151,7 @@ def get200_model204_no_model_default_error201_invalid( :rtype: ~httpinfrastructure.models.MyException or None :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.MyException"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.MyException"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -198,7 +198,7 @@ def get200_model204_no_model_default_error202_none( :rtype: ~httpinfrastructure.models.MyException or None :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.MyException"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.MyException"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) @@ -245,7 +245,7 @@ def get200_model204_no_model_default_error400_valid( :rtype: ~httpinfrastructure.models.MyException or None :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.MyException"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.MyException"]] error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} error_map.update(kwargs.pop('error_map', {})) diff --git a/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/aio/operations_async/_pet_operations_async.py b/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/aio/operations_async/_pet_operations_async.py index e043a5e40fb..0c4d28e775f 100644 --- a/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/aio/operations_async/_pet_operations_async.py +++ b/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/aio/operations_async/_pet_operations_async.py @@ -55,7 +55,7 @@ async def get_pet_by_id( :rtype: ~xmserrorresponse.models.Pet or None :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.Pet"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Pet"]] error_map = { 409: ResourceExistsError, 400: HttpResponseError, diff --git a/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/operations/_pet_operations.py b/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/operations/_pet_operations.py index 9d8e8b69552..d92e436ca80 100644 --- a/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/operations/_pet_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/operations/_pet_operations.py @@ -60,7 +60,7 @@ def get_pet_by_id( :rtype: ~xmserrorresponse.models.Pet or None :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.Pet"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["models.Pet"]] error_map = { 409: ResourceExistsError, 400: HttpResponseError, From 2393cda1f982892c4b99c320025d3957364a0e12 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 28 May 2020 12:08:55 -0400 Subject: [PATCH 4/8] fixed to only look at successful responses in checking whether operation has optional return type --- autorest/codegen/models/operation.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/autorest/codegen/models/operation.py b/autorest/codegen/models/operation.py index 7066dcb91cc..431e2e6ee31 100644 --- a/autorest/codegen/models/operation.py +++ b/autorest/codegen/models/operation.py @@ -167,7 +167,9 @@ def is_stream_response(self) -> bool: @property def has_optional_return_type(self) -> bool: - """Has optional return type if there are multiple response types where some have bodies and some are None""" + """Has optional return type if there are multiple successful response types where some have + bodies and some are None + """ # successful status codes of responses that have bodies status_codes_for_responses_with_bodies = [ @@ -175,7 +177,12 @@ def has_optional_return_type(self) -> bool: if self.get_response_from_status(code).has_body ] - if self.has_response_body and len(self.responses) > 1: + successful_responses = [ + response for response in self.responses + if any(code in self.success_status_code for code in response.status_codes) + ] + + if self.has_response_body and len(successful_responses) > 1: if len(self.success_status_code) != len(status_codes_for_responses_with_bodies): return True return False From 5e139fe2ff3ea1dd32d3d54eb7d8d07aa711a543 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 28 May 2020 13:08:25 -0400 Subject: [PATCH 5/8] added unittests --- test/unittests/test_optional_return_type.py | 120 ++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 test/unittests/test_optional_return_type.py diff --git a/test/unittests/test_optional_return_type.py b/test/unittests/test_optional_return_type.py new file mode 100644 index 00000000000..8528b802b6f --- /dev/null +++ b/test/unittests/test_optional_return_type.py @@ -0,0 +1,120 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +import pytest +from autorest.codegen.models import Operation, LROOperation, PagingOperation, SchemaResponse, CodeModel + +@pytest.fixture +def operation(): + return Operation( + yaml_data={}, + name="optional_return_type_test", + description="Operation to test optional return types", + url="http://www.optional_return_type.com", + method="method", + api_versions=set(["2020-05-01"]), + requests=[] + ) + +@pytest.fixture +def lro_operation(): + return LROOperation( + yaml_data={}, + name="lro_optional_return_type_test", + description="LRO Operation to test optional return types", + url="http://www.optional_return_type.com", + method="method", + api_versions=set(["2020-05-01"]), + requests=[] + ) + +@pytest.fixture +def paging_operation(): + return PagingOperation( + yaml_data={"extensions": {"x-ms-pageable": {}}}, + name="paging_optional_return_type_test", + description="Paging Operation to test optional return types", + url="http://www.optional_return_type.com", + method="method", + api_versions=set(["2020-05-01"]), + requests=[] + ) + +def test_success_with_body_and_fail_no_body(operation): + operation.responses = [ + SchemaResponse( + yaml_data={}, media_types=["application/xml", "text/json"], headers=[], binary=False, schema={"a": "b"}, status_codes=[200] + ), + SchemaResponse( + yaml_data={}, media_types=["application/xml", "text/json"], headers=[], binary=False, schema={"a": "b"}, status_codes=[202] + ), + SchemaResponse( + yaml_data={}, media_types=["application/json", "text/json"], headers=[], binary=False, schema=None, status_codes=["default"] + ) + ] + + assert operation.has_optional_return_type is False + +def test_success_no_body_fail_with_body(operation): + operation.responses = [ + SchemaResponse( + yaml_data={}, media_types=["application/xml", "text/json"], headers=[], binary=False, schema=None, status_codes=[200] + ), + SchemaResponse( + yaml_data={}, media_types=["application/json", "text/json"], headers=[], binary=False, schema={"a": "b"}, status_codes=["default"] + ) + ] + + assert operation.has_optional_return_type is False + +def test_optional_return_type_operation(operation): + operation.responses = [ + SchemaResponse( + yaml_data={}, media_types=["application/xml", "text/json"], headers=[], binary=False, schema={"a": "b"}, status_codes=[200] + ), + SchemaResponse( + yaml_data={}, media_types=["application/json", "text/json"], headers=[], binary=False, schema=None, status_codes=[202] + ), + SchemaResponse( + yaml_data={}, media_types=["application/json", "text/json"], headers=[], binary=False, schema={"a": "b"}, status_codes=["default"] + ) + ] + + assert operation.has_optional_return_type is True + +def test_lro_operation(lro_operation): + lro_operation.responses = [ + SchemaResponse( + yaml_data={}, media_types=["application/xml", "text/json"], headers=[], binary=False, schema={"a": "b"}, status_codes=[200] + ), + SchemaResponse( + yaml_data={}, media_types=["application/json", "text/json"], headers=[], binary=False, schema=None, status_codes=[202] + ), + SchemaResponse( + yaml_data={}, media_types=["application/json", "text/json"], headers=[], binary=False, schema={"a": "b"}, status_codes=["default"] + ) + ] + + assert lro_operation.has_optional_return_type is False + + lro_initial_function = CodeModel._lro_initial_function(lro_operation) + + assert lro_initial_function.has_optional_return_type is True + +def test_paging_operation(paging_operation): + paging_operation.responses = [ + SchemaResponse( + yaml_data={}, media_types=["application/xml", "text/json"], headers=[], binary=False, schema={"a": "b"}, status_codes=[200] + ), + SchemaResponse( + yaml_data={}, media_types=["application/json", "text/json"], headers=[], binary=False, schema=None, status_codes=[202] + ), + SchemaResponse( + yaml_data={}, media_types=["application/json", "text/json"], headers=[], binary=False, schema={"a": "b"}, status_codes=["default"] + ) + ] + + assert paging_operation.has_optional_return_type is False From b6191305577f8a40b37cff7c024023697a205d21 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 28 May 2020 16:06:59 -0400 Subject: [PATCH 6/8] fixed mypy --- autorest/codegen/models/operation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autorest/codegen/models/operation.py b/autorest/codegen/models/operation.py index 431e2e6ee31..2b4f25b1f89 100644 --- a/autorest/codegen/models/operation.py +++ b/autorest/codegen/models/operation.py @@ -174,7 +174,7 @@ def has_optional_return_type(self) -> bool: # successful status codes of responses that have bodies status_codes_for_responses_with_bodies = [ code for code in self.success_status_code - if self.get_response_from_status(code).has_body + if isinstance(code, int) and self.get_response_from_status(code).has_body ] successful_responses = [ From 36520da71550415b3773f9629f4a5773b2df42d5 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Fri, 29 May 2020 14:42:35 -0400 Subject: [PATCH 7/8] updated changelog --- ChangeLog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index e2e097f6f53..ab90bc1e427 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -5,6 +5,8 @@ Modelerfour version: 4.13.351 **Bug Fixes** - Corrected generation of the item name of paging response when extracting data #648 +- Corrected return type typing annotation for operations that return an optional body #656 +- Fixed mypy issue by only setting the generated `deserialized` variable to None if the operation has an optional return typ #656 ### 2020-05-22 - 5.0.0-preview.8 Modelerfour version: 4.13.351 From dd12da125d606083fc7295af36d3f7b84f6b991b Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Fri, 29 May 2020 18:16:55 -0400 Subject: [PATCH 8/8] make logic prettier --- autorest/codegen/models/operation.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/autorest/codegen/models/operation.py b/autorest/codegen/models/operation.py index 2b4f25b1f89..5ae527ea5c3 100644 --- a/autorest/codegen/models/operation.py +++ b/autorest/codegen/models/operation.py @@ -182,10 +182,11 @@ def has_optional_return_type(self) -> bool: if any(code in self.success_status_code for code in response.status_codes) ] - if self.has_response_body and len(successful_responses) > 1: - if len(self.success_status_code) != len(status_codes_for_responses_with_bodies): - return True - return False + return ( + self.has_response_body and + len(successful_responses) > 1 and + len(self.success_status_code) != len(status_codes_for_responses_with_bodies) + ) @staticmethod