Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions autorest/codegen/models/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,20 +223,16 @@ def serialization_type(self) -> str:
def docstring_type(self) -> str:
return self.multiple_media_types_docstring_type or self.schema.docstring_type

@property
def sync_method_signature(self) -> str:
def method_signature(self, async_mode: bool) -> str:
default_value, default_value_declaration, type_annot = self._default_value()
if default_value is not None or not self.required:
if async_mode:
return f"{self.serialized_name}: {type_annot} = {default_value_declaration},"
return f"{self.serialized_name}={default_value_declaration}, # type: {type_annot}"
if async_mode:
return f"{self.serialized_name}: {type_annot},"
return f"{self.serialized_name}, # type: {type_annot}"

@property
def async_method_signature(self) -> str:
default_value, default_value_declaration, type_annot = self._default_value()
if default_value is not None or not self.required:
return f"{self.serialized_name}: {type_annot} = {default_value_declaration}"
return f"{self.serialized_name}: {type_annot}"

@property
def full_serialized_name(self) -> str:
origin_name = self.serialized_name
Expand Down
9 changes: 2 additions & 7 deletions autorest/codegen/models/parameter_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,8 @@ def method(self) -> List[Parameter]:
signature_parameters = signature_parameters_no_default_value + signature_parameters_default_value
return signature_parameters

@property
def sync_method_signature(self) -> List[str]:
return [parameter.sync_method_signature for parameter in self.method]

@property
def async_method_signature(self) -> List[str]:
return [parameter.async_method_signature for parameter in self.method]
def method_signature(self, async_mode: bool) -> List[str]:
return [parameter.method_signature(async_mode) for parameter in self.method]

@property
def is_flattened(self) -> bool:
Expand Down
11 changes: 2 additions & 9 deletions autorest/codegen/templates/config.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
{% macro method_signature() %}
def __init__(
self,
{% if async_mode %}
{% for param_signature in code_model.global_parameters.async_method_signature %}
{{ param_signature }},
{% endfor %}
**kwargs: Any
{% else %}
{% for param_signature in code_model.global_parameters.sync_method_signature %}
{% for param_signature in code_model.global_parameters.method_signature(async_mode) %}
{{ param_signature }}
{% endfor %}
**kwargs # type: Any
{% endif %}
{{ "**kwargs: Any" if async_mode else "**kwargs # type: Any" }}
){{" -> None" if async_mode else "" }}:{% endmacro %}
{# actual template starts here #}
# coding=utf-8
Expand Down
4 changes: 2 additions & 2 deletions autorest/codegen/templates/metadata.json.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"sync": {
{% for gp in sync_global_parameters.method %}
{{ gp.serialized_name | tojson }}: {
"signature": {{ gp.sync_method_signature | tojson }},
"signature": {{ gp.method_signature(False) | tojson }},
"description": {{ gp.description | tojson }},
"docstring_type": {{ gp.docstring_type | tojson }},
"required": {{ gp.required | tojson }}
Expand All @@ -29,7 +29,7 @@
"async": {
{% for gp in async_global_parameters.method %}
{{ gp.serialized_name | tojson }}: {
"signature": {{ (gp.async_method_signature + ",") | tojson }},
"signature": {{ (gp.method_signature(True)) | tojson }},
"description": {{ gp.description | tojson }},
"docstring_type": {{ gp.docstring_type | tojson }},
"required": {{ gp.required | tojson }}
Expand Down
18 changes: 5 additions & 13 deletions autorest/codegen/templates/operation_tools.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,13 @@ else ((return_type_wrapper | join("[") + "[") if return_type_wrapper else "") ~
{# get method signature #}
{% macro method_signature(operation, operation_name, async_mode, coroutine, return_type_wrapper, return_type=None) %}
{{ "async " if coroutine else "" }}def {{ operation_name }}(
{% if async_mode %}
self,
{% for param_signature in operation.parameters.async_method_signature %}
{{ param_signature }},
{% endfor %}
**kwargs
){{ async_return_type_annotation(operation, return_type_wrapper, return_type) }}:
{% else %}
self,
{% for param_signature in operation.parameters.sync_method_signature %}
{% for param_signature in operation.parameters.method_signature(async_mode) %}
{{ param_signature }}
{% endfor %}
**kwargs # type: Any
):
{% endif %}{% endmacro %}
{% endfor %}
{{ "**kwargs: Any" if async_mode else "**kwargs # type: Any" }}
){{ async_return_type_annotation(operation, return_type_wrapper, return_type) if async_mode }}:
{% endmacro %}

{# content type docstring #}
{% macro content_type_docstring(operation) %}
Expand Down
20 changes: 5 additions & 15 deletions autorest/codegen/templates/service_client.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,13 @@
{% macro method_signature() %}
def __init__(
self,
{% if async_mode %}
{% for param_signature in code_model.global_parameters.async_method_signature %}
{{ param_signature }},
{% endfor %}
{% if code_model.base_url %}
{{ code_model.base_url_method_signature(True) }}
{% endif %}
**kwargs: Any
{% else %}
{% for param_signature in code_model.global_parameters.sync_method_signature %}
{% for param_signature in code_model.global_parameters.method_signature(async_mode) %}
{{ param_signature }}
{% endfor %}
{% if code_model.base_url %}
{{ code_model.base_url_method_signature(False) }}
{% endif %}
**kwargs # type: Any
{% endfor %}
{% if code_model.base_url %}
{{ code_model.base_url_method_signature(async_mode) }}
{% endif %}
{{ "**kwargs: Any" if async_mode else "**kwargs # type: Any" }}
){{" -> None" if async_mode else "" }}:{% endmacro %}
{% set config_signature = code_model.global_parameters.method|join(', ', attribute='serialized_name') ~ (", " if code_model.global_parameters.method else "") %}
{% set has_mixin_operation_group = code_model.operation_groups|selectattr("is_empty_operation_group")|first %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, client, config, serializer, deserializer) -> None:

async def head200(
self,
**kwargs
**kwargs: Any
) -> None:
"""Return 200 status code if successful.

Expand Down Expand Up @@ -74,7 +74,7 @@ async def head200(

async def head204(
self,
**kwargs
**kwargs: Any
) -> None:
"""Return 204 status code if successful.

Expand Down Expand Up @@ -113,7 +113,7 @@ async def head204(

async def head404(
self,
**kwargs
**kwargs: Any
) -> None:
"""Return 404 status code if successful.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, client, config, serializer, deserializer) -> None:

async def head200(
self,
**kwargs
**kwargs: Any
) -> None:
"""Return 200 status code if successful.

Expand Down Expand Up @@ -74,7 +74,7 @@ async def head200(

async def head204(
self,
**kwargs
**kwargs: Any
) -> None:
"""Return 204 status code if successful.

Expand Down Expand Up @@ -113,7 +113,7 @@ async def head204(

async def head404(
self,
**kwargs
**kwargs: Any
) -> None:
"""Return 404 status code if successful.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PollingPagingExampleOperationsMixin:
async def _basic_polling_initial(
self,
product: Optional["_models.Product"] = None,
**kwargs
**kwargs: Any
) -> Optional["_models.Product"]:
cls = kwargs.pop('cls', None) # type: ClsType[Optional["_models.Product"]]
error_map = {
Expand Down Expand Up @@ -74,7 +74,7 @@ async def _basic_polling_initial(
async def begin_basic_polling(
self,
product: Optional["_models.Product"] = None,
**kwargs
**kwargs: Any
) -> AsyncCustomPoller["_models.Product"]:
"""A simple polling operation.

Expand Down Expand Up @@ -130,7 +130,7 @@ def get_long_running_output(pipeline_response):

def basic_paging(
self,
**kwargs
**kwargs: Any
) -> AsyncIterable["_models.ProductResult"]:
"""A simple paging operation.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, client, config, serializer, deserializer) -> None:

async def head200(
self,
**kwargs
**kwargs: Any
) -> bool:
"""Return 200 status code if successful.

Expand Down Expand Up @@ -76,7 +76,7 @@ async def head200(

async def head204(
self,
**kwargs
**kwargs: Any
) -> bool:
"""Return 204 status code if successful.

Expand Down Expand Up @@ -116,7 +116,7 @@ async def head204(

async def head404(
self,
**kwargs
**kwargs: Any
) -> bool:
"""Return 404 status code if successful.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MultiapiServiceClientOperationsMixin(object):
async def begin_test_lro(
self,
product: Optional["_models.Product"] = None,
**kwargs
**kwargs: Any
) -> AsyncLROPoller["_models.Product"]:
"""Put in whatever shape of Product you want, will return a Product with id equal to 100.

Expand Down Expand Up @@ -59,7 +59,7 @@ def begin_test_lro_and_paging(
self,
client_request_id: Optional[str] = None,
test_lro_and_paging_options: Optional["_models.TestLroAndPagingOptions"] = None,
**kwargs
**kwargs: Any
) -> AsyncLROPoller[AsyncItemPaged["_models.PagingResult"]]:
"""A long-running paging operation that includes a nextLink that has 10 pages.

Expand Down Expand Up @@ -95,7 +95,7 @@ async def test_different_calls(
greeting_in_english: str,
greeting_in_chinese: Optional[str] = None,
greeting_in_french: Optional[str] = None,
**kwargs
**kwargs: Any
) -> None:
"""Has added parameters across the API versions.

Expand Down Expand Up @@ -131,7 +131,7 @@ async def test_one(
self,
id: int,
message: Optional[str] = None,
**kwargs
**kwargs: Any
) -> None:
"""TestOne should be in an FirstVersionOperationsMixin.

Expand Down Expand Up @@ -161,7 +161,7 @@ async def test_one(

def test_paging(
self,
**kwargs
**kwargs: Any
) -> AsyncItemPaged["_models.PagingResult"]:
"""Returns ModelThree with optionalProperty 'paged'.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
},
"async": {
"coroutine": true,
"signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs\n) -\u003e None:\n",
"signature": "async def test_one(\n self,\n id: int,\n message: Optional[str] = None,\n **kwargs: Any\n) -\u003e None:\n",
"doc": "\"\"\"TestOne should be in an FirstVersionOperationsMixin.\n\n:param id: An int parameter.\n:type id: int\n:param message: An optional string parameter.\n:type message: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: None, or the result of cls(response)\n:rtype: None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\""
},
"call": "id, message"
Expand All @@ -111,7 +111,7 @@
},
"async": {
"coroutine": true,
"signature": "async def _test_lro_initial(\n self,\n product: Optional[\"_models.Product\"] = None,\n **kwargs\n) -\u003e Optional[\"_models.Product\"]:\n",
"signature": "async def _test_lro_initial(\n self,\n product: Optional[\"_models.Product\"] = None,\n **kwargs: Any\n) -\u003e Optional[\"_models.Product\"]:\n",
"doc": "\"\"\"\n\n:param product: Product to put.\n:type product: ~azure.multiapi.sample.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: ~azure.multiapi.sample.v1.models.Product or None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\""
},
"call": "product"
Expand All @@ -123,7 +123,7 @@
},
"async": {
"coroutine": true,
"signature": "async def begin_test_lro(\n self,\n product: Optional[\"_models.Product\"] = None,\n **kwargs\n) -\u003e AsyncLROPoller[\"_models.Product\"]:\n",
"signature": "async def begin_test_lro(\n self,\n product: Optional[\"_models.Product\"] = None,\n **kwargs: Any\n) -\u003e AsyncLROPoller[\"_models.Product\"]:\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: ~azure.multiapi.sample.v1.models.Product\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: By default, your polling method will be AsyncARMPolling.\n Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy.\n:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of AsyncLROPoller that returns either Product or the result of cls(response)\n:rtype: ~azure.core.polling.AsyncLROPoller[~azure.multiapi.sample.v1.models.Product]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\""
},
"call": "product"
Expand All @@ -135,7 +135,7 @@
},
"async": {
"coroutine": true,
"signature": "async def _test_lro_and_paging_initial(\n self,\n client_request_id: Optional[str] = None,\n test_lro_and_paging_options: Optional[\"_models.TestLroAndPagingOptions\"] = None,\n **kwargs\n) -\u003e \"_models.PagingResult\":\n",
"signature": "async def _test_lro_and_paging_initial(\n self,\n client_request_id: Optional[str] = None,\n test_lro_and_paging_options: Optional[\"_models.TestLroAndPagingOptions\"] = None,\n **kwargs: Any\n) -\u003e \"_models.PagingResult\":\n",
"doc": "\"\"\"\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~azure.multiapi.sample.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: PagingResult, or the result of cls(response)\n:rtype: ~azure.multiapi.sample.v1.models.PagingResult\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\""
},
"call": "client_request_id, test_lro_and_paging_options"
Expand All @@ -147,7 +147,7 @@
},
"async": {
"coroutine": false,
"signature": "def begin_test_lro_and_paging(\n self,\n client_request_id: Optional[str] = None,\n test_lro_and_paging_options: Optional[\"_models.TestLroAndPagingOptions\"] = None,\n **kwargs\n) -\u003e AsyncLROPoller[AsyncItemPaged[\"_models.PagingResult\"]]:\n",
"signature": "def begin_test_lro_and_paging(\n self,\n client_request_id: Optional[str] = None,\n test_lro_and_paging_options: Optional[\"_models.TestLroAndPagingOptions\"] = None,\n **kwargs: Any\n) -\u003e AsyncLROPoller[AsyncItemPaged[\"_models.PagingResult\"]]:\n",
"doc": "\"\"\"A long-running paging operation that includes a nextLink that has 10 pages.\n\n:param client_request_id:\n:type client_request_id: str\n:param test_lro_and_paging_options: Parameter group.\n:type test_lro_and_paging_options: ~azure.multiapi.sample.v1.models.TestLroAndPagingOptions\n:keyword callable cls: A custom type or function that will be passed the direct response\n:keyword str continuation_token: A continuation token to restart a poller from a saved state.\n:keyword polling: By default, your polling method will be AsyncARMPolling.\n Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy.\n:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod\n:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.\n:return: An instance of AsyncLROPoller that returns an iterator like instance of either PagingResult or the result of cls(response)\n:rtype: ~azure.core.polling.AsyncLROPoller[~azure.core.async_paging.AsyncItemPaged[~azure.multiapi.sample.v1.models.PagingResult]]\n:raises ~azure.core.exceptions.HttpResponseError:\n\"\"\""
},
"call": "client_request_id, test_lro_and_paging_options"
Expand All @@ -159,7 +159,7 @@
},
"async": {
"coroutine": true,
"signature": "async def test_different_calls(\n self,\n greeting_in_english: str,\n **kwargs\n) -\u003e None:\n",
"signature": "async def test_different_calls(\n self,\n greeting_in_english: str,\n **kwargs: Any\n) -\u003e None:\n",
"doc": "\"\"\"Has added parameters across the API versions.\n\n:param greeting_in_english: pass in \u0027hello\u0027 to pass test.\n:type greeting_in_english: str\n:keyword callable cls: A custom type or function that will be passed the direct response\n:return: None, or the result of cls(response)\n:rtype: None\n:raises: ~azure.core.exceptions.HttpResponseError\n\"\"\""
},
"call": "greeting_in_english"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def test_one(
self,
id: int,
message: Optional[str] = None,
**kwargs
**kwargs: Any
) -> None:
"""TestOne should be in an FirstVersionOperationsMixin.

Expand Down Expand Up @@ -79,7 +79,7 @@ async def test_one(
async def _test_lro_initial(
self,
product: Optional["_models.Product"] = None,
**kwargs
**kwargs: Any
) -> Optional["_models.Product"]:
cls = kwargs.pop('cls', None) # type: ClsType[Optional["_models.Product"]]
error_map = {
Expand Down Expand Up @@ -128,7 +128,7 @@ async def _test_lro_initial(
async def begin_test_lro(
self,
product: Optional["_models.Product"] = None,
**kwargs
**kwargs: Any
) -> AsyncLROPoller["_models.Product"]:
"""Put in whatever shape of Product you want, will return a Product with id equal to 100.

Expand Down Expand Up @@ -186,7 +186,7 @@ async def _test_lro_and_paging_initial(
self,
client_request_id: Optional[str] = None,
test_lro_and_paging_options: Optional["_models.TestLroAndPagingOptions"] = None,
**kwargs
**kwargs: Any
) -> "_models.PagingResult":
cls = kwargs.pop('cls', None) # type: ClsType["_models.PagingResult"]
error_map = {
Expand Down Expand Up @@ -237,7 +237,7 @@ async def begin_test_lro_and_paging(
self,
client_request_id: Optional[str] = None,
test_lro_and_paging_options: Optional["_models.TestLroAndPagingOptions"] = None,
**kwargs
**kwargs: Any
) -> AsyncLROPoller[AsyncItemPaged["_models.PagingResult"]]:
"""A long-running paging operation that includes a nextLink that has 10 pages.

Expand Down Expand Up @@ -355,7 +355,7 @@ async def internal_get_next(next_link=None):
async def test_different_calls(
self,
greeting_in_english: str,
**kwargs
**kwargs: Any
) -> None:
"""Has added parameters across the API versions.

Expand Down
Loading