@autorest/python 5.18.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChangeLog.md +58 -13
- package/README.md +9 -0
- package/autorest/codegen/__init__.py +24 -30
- package/autorest/codegen/models/base_builder.py +17 -6
- package/autorest/codegen/models/client.py +9 -6
- package/autorest/codegen/models/code_model.py +20 -14
- package/autorest/codegen/models/imports.py +57 -2
- package/autorest/codegen/models/lro_operation.py +4 -6
- package/autorest/codegen/models/lro_paging_operation.py +3 -9
- package/autorest/codegen/models/model_type.py +1 -6
- package/autorest/codegen/models/operation.py +47 -79
- package/autorest/codegen/models/operation_group.py +10 -9
- package/autorest/codegen/models/paging_operation.py +19 -7
- package/autorest/codegen/models/parameter.py +3 -7
- package/autorest/codegen/models/parameter_list.py +20 -36
- package/autorest/codegen/models/request_builder.py +31 -42
- package/autorest/codegen/serializers/__init__.py +12 -50
- package/autorest/codegen/serializers/builder_serializer.py +53 -40
- package/autorest/codegen/serializers/client_serializer.py +22 -31
- package/autorest/codegen/serializers/general_serializer.py +12 -12
- package/autorest/codegen/serializers/import_serializer.py +11 -22
- package/autorest/codegen/serializers/metadata_serializer.py +0 -2
- package/autorest/codegen/serializers/{model_base_serializer.py → model_serializer.py} +57 -43
- package/autorest/codegen/serializers/operation_groups_serializer.py +3 -7
- package/autorest/codegen/serializers/operations_init_serializer.py +2 -23
- package/autorest/codegen/serializers/patch_serializer.py +1 -3
- package/autorest/codegen/serializers/request_builders_serializer.py +2 -5
- package/autorest/codegen/serializers/utils.py +1 -4
- package/autorest/codegen/templates/client.py.jinja2 +6 -3
- package/autorest/codegen/templates/config.py.jinja2 +2 -2
- package/autorest/codegen/templates/metadata.json.jinja2 +4 -4
- package/autorest/codegen/templates/model_init.py.jinja2 +5 -12
- package/autorest/codegen/templates/operation_group.py.jinja2 +16 -3
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +2 -8
- package/autorest/codegen/templates/operation_tools.jinja2 +3 -1
- package/autorest/codegen/templates/patch.py.jinja2 +1 -2
- package/autorest/codegen/templates/request_builder.py.jinja2 +0 -7
- package/autorest/codegen/templates/request_builders.py.jinja2 +1 -4
- package/autorest/codegen/templates/rest_init.py.jinja2 +3 -8
- package/autorest/codegen/templates/serialization.py.jinja2 +2006 -0
- package/autorest/codegen/templates/setup.py.jinja2 +4 -0
- package/autorest/codegen/templates/vendor.py.jinja2 +10 -0
- package/autorest/m4reformatter/__init__.py +9 -3
- package/autorest/multiapi/models/client.py +12 -2
- package/autorest/multiapi/serializers/__init__.py +17 -8
- package/autorest/multiapi/serializers/import_serializer.py +4 -8
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +1 -1
- package/autorest/preprocess/__init__.py +24 -4
- package/package.json +2 -2
- package/autorest/codegen/serializers/model_generic_serializer.py +0 -32
- package/autorest/codegen/serializers/model_python3_serializer.py +0 -72
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
import logging
|
|
7
6
|
from itertools import chain
|
|
8
7
|
from typing import (
|
|
9
8
|
Dict,
|
|
@@ -43,8 +42,6 @@ from .request_builder import OverloadedRequestBuilder, RequestBuilder
|
|
|
43
42
|
if TYPE_CHECKING:
|
|
44
43
|
from .code_model import CodeModel
|
|
45
44
|
|
|
46
|
-
_LOGGER = logging.getLogger(__name__)
|
|
47
|
-
|
|
48
45
|
ResponseType = TypeVar(
|
|
49
46
|
"ResponseType",
|
|
50
47
|
bound=Union[Response, PagingResponse, LROResponse, LROPagingResponse],
|
|
@@ -67,7 +64,6 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
67
64
|
overloads: Optional[List["Operation"]] = None,
|
|
68
65
|
public: bool = True,
|
|
69
66
|
want_tracing: bool = True,
|
|
70
|
-
abstract: bool = False,
|
|
71
67
|
) -> None:
|
|
72
68
|
super().__init__(
|
|
73
69
|
code_model=code_model,
|
|
@@ -75,7 +71,6 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
75
71
|
name=name,
|
|
76
72
|
parameters=parameters,
|
|
77
73
|
overloads=overloads,
|
|
78
|
-
abstract=abstract,
|
|
79
74
|
want_tracing=want_tracing,
|
|
80
75
|
)
|
|
81
76
|
self.overloads: List["Operation"] = overloads or []
|
|
@@ -204,9 +199,8 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
204
199
|
file_import.add_submodule_import(
|
|
205
200
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
206
201
|
)
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
file_import.merge(param.imports(async_mode, **kwargs))
|
|
202
|
+
for param in self.parameters.method:
|
|
203
|
+
file_import.merge(param.imports(async_mode, **kwargs))
|
|
210
204
|
|
|
211
205
|
response_types = [
|
|
212
206
|
r.type_annotation(async_mode=async_mode) for r in self.responses if r.type
|
|
@@ -218,6 +212,8 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
218
212
|
return file_import
|
|
219
213
|
|
|
220
214
|
def imports_for_multiapi(self, async_mode: bool, **kwargs: Any) -> FileImport:
|
|
215
|
+
if self.abstract:
|
|
216
|
+
return FileImport()
|
|
221
217
|
file_import = self._imports_shared(async_mode, **kwargs)
|
|
222
218
|
for response in self.responses:
|
|
223
219
|
file_import.merge(
|
|
@@ -273,22 +269,16 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
273
269
|
alias="rest",
|
|
274
270
|
)
|
|
275
271
|
if self.code_model.options["builders_visibility"] == "embedded" and async_mode:
|
|
276
|
-
suffix = (
|
|
277
|
-
"_py3"
|
|
278
|
-
if self.code_model.options["add_python3_operation_files"]
|
|
279
|
-
and not self.code_model.options["python3_only"]
|
|
280
|
-
else ""
|
|
281
|
-
)
|
|
282
272
|
file_import.add_submodule_import(
|
|
283
|
-
f"...{self.code_model.operations_folder_name}.{self.filename}
|
|
273
|
+
f"...{self.code_model.operations_folder_name}.{self.filename}",
|
|
284
274
|
request_builder.name,
|
|
285
275
|
import_type=ImportType.LOCAL,
|
|
286
276
|
)
|
|
287
277
|
return file_import
|
|
288
278
|
|
|
289
|
-
def imports(
|
|
290
|
-
self
|
|
291
|
-
|
|
279
|
+
def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
|
|
280
|
+
if self.abstract:
|
|
281
|
+
return FileImport()
|
|
292
282
|
file_import = self._imports_shared(async_mode, **kwargs)
|
|
293
283
|
|
|
294
284
|
for response in self.responses:
|
|
@@ -301,48 +291,44 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
301
291
|
file_import.merge(self.parameters.body_parameter.type.imports(**kwargs))
|
|
302
292
|
|
|
303
293
|
# Exceptions
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
"azure.core.exceptions", "map_error", ImportType.AZURECORE
|
|
309
|
-
)
|
|
310
|
-
if self.code_model.options["azure_arm"]:
|
|
311
|
-
file_import.add_submodule_import(
|
|
312
|
-
"azure.mgmt.core.exceptions", "ARMErrorFormat", ImportType.AZURECORE
|
|
313
|
-
)
|
|
314
|
-
file_import.add_submodule_import(
|
|
315
|
-
"azure.core.exceptions", "HttpResponseError", ImportType.AZURECORE
|
|
316
|
-
)
|
|
294
|
+
file_import.add_submodule_import(
|
|
295
|
+
"azure.core.exceptions", "map_error", ImportType.AZURECORE
|
|
296
|
+
)
|
|
297
|
+
if self.code_model.options["azure_arm"]:
|
|
317
298
|
file_import.add_submodule_import(
|
|
318
|
-
"azure.core.exceptions",
|
|
319
|
-
"ClientAuthenticationError",
|
|
320
|
-
ImportType.AZURECORE,
|
|
299
|
+
"azure.mgmt.core.exceptions", "ARMErrorFormat", ImportType.AZURECORE
|
|
321
300
|
)
|
|
301
|
+
file_import.add_submodule_import(
|
|
302
|
+
"azure.core.exceptions", "HttpResponseError", ImportType.AZURECORE
|
|
303
|
+
)
|
|
304
|
+
file_import.add_submodule_import(
|
|
305
|
+
"azure.core.exceptions",
|
|
306
|
+
"ClientAuthenticationError",
|
|
307
|
+
ImportType.AZURECORE,
|
|
308
|
+
)
|
|
309
|
+
file_import.add_submodule_import(
|
|
310
|
+
"azure.core.exceptions", "ResourceNotFoundError", ImportType.AZURECORE
|
|
311
|
+
)
|
|
312
|
+
file_import.add_submodule_import(
|
|
313
|
+
"azure.core.exceptions", "ResourceExistsError", ImportType.AZURECORE
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
if self.has_kwargs_to_pop_with_default(
|
|
317
|
+
self.parameters.kwargs_to_pop, ParameterLocation.HEADER
|
|
318
|
+
) or self.has_kwargs_to_pop_with_default(
|
|
319
|
+
self.parameters.kwargs_to_pop, ParameterLocation.QUERY
|
|
320
|
+
):
|
|
322
321
|
file_import.add_submodule_import(
|
|
323
|
-
"azure.core.
|
|
322
|
+
"azure.core.utils", "case_insensitive_dict", ImportType.AZURECORE
|
|
324
323
|
)
|
|
324
|
+
if self.deprecated:
|
|
325
|
+
file_import.add_import("warnings", ImportType.STDLIB)
|
|
326
|
+
|
|
327
|
+
if self.code_model.need_request_converter:
|
|
328
|
+
relative_path = "..." if async_mode else ".."
|
|
325
329
|
file_import.add_submodule_import(
|
|
326
|
-
"
|
|
330
|
+
f"{relative_path}_vendor", "_convert_request", ImportType.LOCAL
|
|
327
331
|
)
|
|
328
|
-
|
|
329
|
-
kwargs_to_pop = self.parameters.kwargs_to_pop(is_python3_file)
|
|
330
|
-
if self.has_kwargs_to_pop_with_default(
|
|
331
|
-
kwargs_to_pop, ParameterLocation.HEADER
|
|
332
|
-
) or self.has_kwargs_to_pop_with_default(
|
|
333
|
-
kwargs_to_pop, ParameterLocation.QUERY
|
|
334
|
-
):
|
|
335
|
-
file_import.add_submodule_import(
|
|
336
|
-
"azure.core.utils", "case_insensitive_dict", ImportType.AZURECORE
|
|
337
|
-
)
|
|
338
|
-
if self.deprecated:
|
|
339
|
-
file_import.add_import("warnings", ImportType.STDLIB)
|
|
340
|
-
|
|
341
|
-
if self.code_model.need_request_converter:
|
|
342
|
-
relative_path = "..." if async_mode else ".."
|
|
343
|
-
file_import.add_submodule_import(
|
|
344
|
-
f"{relative_path}_vendor", "_convert_request", ImportType.LOCAL
|
|
345
|
-
)
|
|
346
332
|
if async_mode:
|
|
347
333
|
file_import.add_submodule_import(
|
|
348
334
|
"azure.core.pipeline.transport",
|
|
@@ -382,10 +368,9 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
382
368
|
f"distributed_trace",
|
|
383
369
|
ImportType.AZURECORE,
|
|
384
370
|
)
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
)
|
|
371
|
+
file_import.merge(
|
|
372
|
+
self.get_request_builder_import(self.request_builder, async_mode)
|
|
373
|
+
)
|
|
389
374
|
if self.overloads:
|
|
390
375
|
file_import.add_submodule_import("typing", "overload", ImportType.STDLIB)
|
|
391
376
|
return file_import
|
|
@@ -439,20 +424,6 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
439
424
|
cls.from_yaml(overload, code_model)
|
|
440
425
|
for overload in yaml_data.get("overloads", [])
|
|
441
426
|
]
|
|
442
|
-
abstract = False
|
|
443
|
-
if (
|
|
444
|
-
code_model.options["version_tolerant"]
|
|
445
|
-
and parameter_list.has_body
|
|
446
|
-
and isinstance(parameter_list.body_parameter, MultipartBodyParameter)
|
|
447
|
-
):
|
|
448
|
-
_LOGGER.warning(
|
|
449
|
-
'Not going to generate operation "%s" because it has multipart / urlencoded body parameters. '
|
|
450
|
-
"Multipart / urlencoded body parameters are not supported for version tolerant generation right now. "
|
|
451
|
-
'Please write your own custom operation in the "_patch.py" file '
|
|
452
|
-
"following https://aka.ms/azsdk/python/dpcodegen/python/customize",
|
|
453
|
-
name,
|
|
454
|
-
)
|
|
455
|
-
abstract = True
|
|
456
427
|
|
|
457
428
|
return cls(
|
|
458
429
|
yaml_data=yaml_data,
|
|
@@ -464,23 +435,20 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
464
435
|
responses=responses,
|
|
465
436
|
exceptions=exceptions,
|
|
466
437
|
want_tracing=not yaml_data["isOverload"],
|
|
467
|
-
abstract=abstract,
|
|
468
438
|
)
|
|
469
439
|
|
|
470
440
|
|
|
471
441
|
class Operation(OperationBase[Response]):
|
|
472
|
-
def imports(
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
442
|
+
def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
|
|
443
|
+
file_import = super().imports(async_mode, **kwargs)
|
|
444
|
+
if self.abstract:
|
|
445
|
+
return file_import
|
|
476
446
|
if async_mode:
|
|
477
447
|
file_import.add_submodule_import(
|
|
478
448
|
f"azure.core.tracing.decorator_async",
|
|
479
449
|
f"distributed_trace_async",
|
|
480
450
|
ImportType.AZURECORE,
|
|
481
451
|
)
|
|
482
|
-
if self.abstract:
|
|
483
|
-
return file_import
|
|
484
452
|
if (
|
|
485
453
|
self.has_response_body
|
|
486
454
|
and not self.has_optional_return_type
|
|
@@ -36,14 +36,11 @@ class OperationGroup(BaseModel):
|
|
|
36
36
|
def has_abstract_operations(self) -> bool:
|
|
37
37
|
return any(o for o in self.operations if o.abstract)
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
@property
|
|
40
|
+
def base_class(self) -> str:
|
|
40
41
|
base_classes: List[str] = []
|
|
41
42
|
if self.is_mixin and self.code_model.need_mixin_abc:
|
|
42
43
|
base_classes.append("MixinABC")
|
|
43
|
-
if not (async_mode or self.code_model.options["python3_only"]):
|
|
44
|
-
base_classes.append("object")
|
|
45
|
-
if self.has_abstract_operations:
|
|
46
|
-
base_classes.append("abc.ABC")
|
|
47
44
|
return ", ".join(base_classes)
|
|
48
45
|
|
|
49
46
|
def imports_for_multiapi(self, async_mode: bool) -> FileImport:
|
|
@@ -69,15 +66,13 @@ class OperationGroup(BaseModel):
|
|
|
69
66
|
return " # type: ignore"
|
|
70
67
|
return ""
|
|
71
68
|
|
|
72
|
-
def imports(self, async_mode: bool
|
|
69
|
+
def imports(self, async_mode: bool) -> FileImport:
|
|
73
70
|
file_import = FileImport()
|
|
74
71
|
|
|
75
72
|
relative_path = "..." if async_mode else ".."
|
|
76
73
|
for operation in self.operations:
|
|
77
74
|
file_import.merge(
|
|
78
|
-
operation.imports(
|
|
79
|
-
async_mode, is_python3_file, relative_path=relative_path
|
|
80
|
-
)
|
|
75
|
+
operation.imports(async_mode, relative_path=relative_path)
|
|
81
76
|
)
|
|
82
77
|
# for multiapi
|
|
83
78
|
if not self.code_model.options["version_tolerant"]:
|
|
@@ -89,6 +84,12 @@ class OperationGroup(BaseModel):
|
|
|
89
84
|
)
|
|
90
85
|
if self.code_model.need_mixin_abc:
|
|
91
86
|
file_import.add_submodule_import(".._vendor", "MixinABC", ImportType.LOCAL)
|
|
87
|
+
if self.has_abstract_operations:
|
|
88
|
+
file_import.add_submodule_import(
|
|
89
|
+
".._vendor", "raise_if_not_implemented", ImportType.LOCAL
|
|
90
|
+
)
|
|
91
|
+
if all(o.abstract for o in self.operations):
|
|
92
|
+
return file_import
|
|
92
93
|
file_import.add_submodule_import(
|
|
93
94
|
"typing", "TypeVar", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
94
95
|
)
|
|
@@ -38,7 +38,6 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
38
38
|
overloads: Optional[List[Operation]] = None,
|
|
39
39
|
public: bool = True,
|
|
40
40
|
want_tracing: bool = True,
|
|
41
|
-
abstract: bool = False,
|
|
42
41
|
override_success_response_to_200: bool = False,
|
|
43
42
|
) -> None:
|
|
44
43
|
super().__init__(
|
|
@@ -52,7 +51,6 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
52
51
|
overloads=overloads,
|
|
53
52
|
public=public,
|
|
54
53
|
want_tracing=want_tracing,
|
|
55
|
-
abstract=abstract,
|
|
56
54
|
)
|
|
57
55
|
self.next_request_builder: Optional[
|
|
58
56
|
Union[RequestBuilder, OverloadedRequestBuilder]
|
|
@@ -127,11 +125,11 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
127
125
|
def has_optional_return_type(self) -> bool:
|
|
128
126
|
return False
|
|
129
127
|
|
|
130
|
-
def imports(
|
|
131
|
-
self
|
|
132
|
-
|
|
128
|
+
def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
|
|
129
|
+
if self.abstract:
|
|
130
|
+
return FileImport()
|
|
133
131
|
file_import = self._imports_shared(async_mode, **kwargs)
|
|
134
|
-
file_import.merge(super().imports(async_mode,
|
|
132
|
+
file_import.merge(super().imports(async_mode, **kwargs))
|
|
135
133
|
if self.code_model.options["tracing"] and self.want_tracing:
|
|
136
134
|
file_import.add_submodule_import(
|
|
137
135
|
"azure.core.tracing.decorator",
|
|
@@ -142,7 +140,21 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
142
140
|
file_import.merge(
|
|
143
141
|
self.get_request_builder_import(self.next_request_builder, async_mode)
|
|
144
142
|
)
|
|
145
|
-
|
|
143
|
+
elif "api-version" in [
|
|
144
|
+
p.rest_api_name for p in self.code_model.client.parameters
|
|
145
|
+
]:
|
|
146
|
+
file_import.add_submodule_import(
|
|
147
|
+
"urllib.parse", "urlparse", ImportType.STDLIB
|
|
148
|
+
)
|
|
149
|
+
file_import.add_submodule_import(
|
|
150
|
+
"urllib.parse", "urljoin", ImportType.STDLIB
|
|
151
|
+
)
|
|
152
|
+
file_import.add_submodule_import(
|
|
153
|
+
"urllib.parse", "parse_qs", ImportType.STDLIB
|
|
154
|
+
)
|
|
155
|
+
file_import.add_submodule_import(
|
|
156
|
+
"azure.core.utils", "case_insensitive_dict", ImportType.AZURECORE
|
|
157
|
+
)
|
|
146
158
|
return file_import
|
|
147
159
|
|
|
148
160
|
|
|
@@ -179,15 +179,11 @@ class _ParameterBase(
|
|
|
179
179
|
def in_method_signature(self) -> bool:
|
|
180
180
|
...
|
|
181
181
|
|
|
182
|
-
def method_signature(self,
|
|
182
|
+
def method_signature(self, async_mode: bool) -> str:
|
|
183
183
|
type_annot = self.type_annotation(async_mode=async_mode)
|
|
184
|
-
if is_python3_file:
|
|
185
|
-
if self.client_default_value is not None or self.optional:
|
|
186
|
-
return f"{self.client_name}: {type_annot} = {self.client_default_value_declaration},"
|
|
187
|
-
return f"{self.client_name}: {type_annot},"
|
|
188
184
|
if self.client_default_value is not None or self.optional:
|
|
189
|
-
return f"{self.client_name}={self.client_default_value_declaration},
|
|
190
|
-
return f"{self.client_name}
|
|
185
|
+
return f"{self.client_name}: {type_annot} = {self.client_default_value_declaration},"
|
|
186
|
+
return f"{self.client_name}: {type_annot},"
|
|
191
187
|
|
|
192
188
|
|
|
193
189
|
class _BodyParameterBase(_ParameterBase):
|
|
@@ -235,49 +235,36 @@ class _ParameterListBase(
|
|
|
235
235
|
"""Sorted method params. First positional, then keyword only, then kwarg"""
|
|
236
236
|
return self.positional + self.keyword_only + self.kwarg
|
|
237
237
|
|
|
238
|
-
def method_signature(self,
|
|
238
|
+
def method_signature(self, async_mode: bool) -> List[str]:
|
|
239
239
|
"""Method signature for this parameter list."""
|
|
240
240
|
return method_signature_helper(
|
|
241
|
-
positional=self.method_signature_positional(
|
|
242
|
-
keyword_only=self.method_signature_keyword_only(
|
|
243
|
-
|
|
244
|
-
),
|
|
245
|
-
kwarg_params=self.method_signature_kwargs(is_python3_file),
|
|
241
|
+
positional=self.method_signature_positional(async_mode),
|
|
242
|
+
keyword_only=self.method_signature_keyword_only(async_mode),
|
|
243
|
+
kwarg_params=self.method_signature_kwargs,
|
|
246
244
|
)
|
|
247
245
|
|
|
248
|
-
def method_signature_positional(
|
|
249
|
-
self, is_python3_file: bool, async_mode: bool
|
|
250
|
-
) -> List[str]:
|
|
246
|
+
def method_signature_positional(self, async_mode: bool) -> List[str]:
|
|
251
247
|
"""Signature for positional parameters"""
|
|
252
|
-
return [
|
|
253
|
-
parameter.method_signature(is_python3_file, async_mode)
|
|
254
|
-
for parameter in self.positional
|
|
255
|
-
]
|
|
248
|
+
return [parameter.method_signature(async_mode) for parameter in self.positional]
|
|
256
249
|
|
|
257
|
-
def method_signature_keyword_only(
|
|
258
|
-
self, is_python3_file: bool, async_mode: bool
|
|
259
|
-
) -> List[str]:
|
|
250
|
+
def method_signature_keyword_only(self, async_mode: bool) -> List[str]:
|
|
260
251
|
"""Signature for keyword only parameters"""
|
|
261
|
-
if not
|
|
252
|
+
if not self.keyword_only:
|
|
262
253
|
return []
|
|
263
254
|
return ["*,"] + [
|
|
264
|
-
parameter.method_signature(
|
|
265
|
-
for parameter in self.keyword_only
|
|
255
|
+
parameter.method_signature(async_mode) for parameter in self.keyword_only
|
|
266
256
|
]
|
|
267
257
|
|
|
268
|
-
@
|
|
269
|
-
def method_signature_kwargs(
|
|
258
|
+
@property
|
|
259
|
+
def method_signature_kwargs(self) -> List[str]:
|
|
270
260
|
"""Signature for kwargs"""
|
|
271
|
-
return ["**kwargs: Any"]
|
|
261
|
+
return ["**kwargs: Any"]
|
|
272
262
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
) -> List[Union[ParameterType, BodyParameterType]]:
|
|
263
|
+
@property
|
|
264
|
+
def kwargs_to_pop(self) -> List[Union[ParameterType, BodyParameterType]]:
|
|
276
265
|
"""Method kwargs we want to pop"""
|
|
277
266
|
# don't want to pop bodies unless it's a constant
|
|
278
267
|
kwargs_to_pop = self.kwarg
|
|
279
|
-
if not is_python3_file:
|
|
280
|
-
kwargs_to_pop += self.keyword_only
|
|
281
268
|
return [
|
|
282
269
|
k
|
|
283
270
|
for k in kwargs_to_pop
|
|
@@ -416,14 +403,12 @@ class RequestBuilderParameterList(_RequestBuilderParameterList):
|
|
|
416
403
|
class OverloadedRequestBuilderParameterList(_RequestBuilderParameterList):
|
|
417
404
|
"""Parameter list for OverloadedRequestBuilder"""
|
|
418
405
|
|
|
419
|
-
def method_signature_keyword_only(
|
|
420
|
-
self, is_python3_file: bool, async_mode: bool
|
|
421
|
-
) -> List[str]:
|
|
406
|
+
def method_signature_keyword_only(self, async_mode: bool) -> List[str]:
|
|
422
407
|
"""Signature for keyword only parameters"""
|
|
423
|
-
if not
|
|
408
|
+
if not self.keyword_only:
|
|
424
409
|
return []
|
|
425
410
|
return ["*,"] + [
|
|
426
|
-
parameter.method_signature(
|
|
411
|
+
parameter.method_signature(async_mode)
|
|
427
412
|
for parameter in self.keyword_only
|
|
428
413
|
if parameter.location != ParameterLocation.BODY
|
|
429
414
|
]
|
|
@@ -478,13 +463,12 @@ class ClientGlobalParameterList(_ClientGlobalParameterList[ClientParameter]):
|
|
|
478
463
|
except StopIteration:
|
|
479
464
|
return None
|
|
480
465
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
) -> List[Union[ClientParameter, BodyParameter]]:
|
|
466
|
+
@property
|
|
467
|
+
def kwargs_to_pop(self) -> List[Union[ClientParameter, BodyParameter]]:
|
|
484
468
|
"""We only want to pass base url path parameters in the client"""
|
|
485
469
|
return [
|
|
486
470
|
k
|
|
487
|
-
for k in super().kwargs_to_pop
|
|
471
|
+
for k in super().kwargs_to_pop
|
|
488
472
|
if k.location == ParameterLocation.ENDPOINT_PATH
|
|
489
473
|
]
|
|
490
474
|
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
import logging
|
|
7
6
|
from typing import (
|
|
8
7
|
Any,
|
|
9
8
|
Callable,
|
|
@@ -21,13 +20,11 @@ from .parameter_list import (
|
|
|
21
20
|
RequestBuilderParameterList,
|
|
22
21
|
OverloadedRequestBuilderParameterList,
|
|
23
22
|
)
|
|
24
|
-
from .imports import FileImport, ImportType, TypingSection
|
|
25
|
-
from .request_builder_parameter import RequestBuilderMultipartBodyParameter
|
|
23
|
+
from .imports import FileImport, ImportType, TypingSection, MsrestImportType
|
|
26
24
|
|
|
27
25
|
if TYPE_CHECKING:
|
|
28
26
|
from .code_model import CodeModel
|
|
29
27
|
|
|
30
|
-
_LOGGER = logging.getLogger(__name__)
|
|
31
28
|
ParameterListType = TypeVar(
|
|
32
29
|
"ParameterListType",
|
|
33
30
|
bound=Union[RequestBuilderParameterList, OverloadedRequestBuilderParameterList],
|
|
@@ -43,7 +40,6 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
43
40
|
parameters: ParameterListType,
|
|
44
41
|
*,
|
|
45
42
|
overloads: Optional[List["RequestBuilder"]] = None,
|
|
46
|
-
abstract: bool = False,
|
|
47
43
|
) -> None:
|
|
48
44
|
super().__init__(
|
|
49
45
|
code_model=code_model,
|
|
@@ -51,7 +47,6 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
51
47
|
name=name,
|
|
52
48
|
parameters=parameters,
|
|
53
49
|
overloads=overloads,
|
|
54
|
-
abstract=abstract,
|
|
55
50
|
want_tracing=False,
|
|
56
51
|
)
|
|
57
52
|
self.overloads: List["RequestBuilder"] = overloads or []
|
|
@@ -73,34 +68,45 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
73
68
|
|
|
74
69
|
def imports(self) -> FileImport:
|
|
75
70
|
file_import = FileImport()
|
|
76
|
-
if
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
if self.abstract:
|
|
72
|
+
return file_import
|
|
73
|
+
for parameter in self.parameters.method:
|
|
74
|
+
file_import.merge(parameter.imports(async_mode=False))
|
|
79
75
|
|
|
80
76
|
file_import.add_submodule_import(
|
|
81
77
|
"azure.core.rest",
|
|
82
78
|
"HttpRequest",
|
|
83
79
|
ImportType.AZURECORE,
|
|
84
80
|
)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
81
|
+
|
|
82
|
+
if self.parameters.path:
|
|
83
|
+
relative_path = ".."
|
|
84
|
+
if (
|
|
85
|
+
not self.code_model.options["builders_visibility"] == "embedded"
|
|
86
|
+
and self.group_name
|
|
87
|
+
):
|
|
88
|
+
relative_path = "..." if self.group_name else ".."
|
|
89
|
+
file_import.add_submodule_import(
|
|
90
|
+
f"{relative_path}_vendor", "_format_url_section", ImportType.LOCAL
|
|
91
|
+
)
|
|
92
|
+
if self.parameters.headers or self.parameters.query:
|
|
93
|
+
file_import.add_submodule_import(
|
|
94
|
+
"azure.core.utils", "case_insensitive_dict", ImportType.AZURECORE
|
|
95
|
+
)
|
|
100
96
|
file_import.add_submodule_import(
|
|
101
97
|
"typing", "Any", ImportType.STDLIB, typing_section=TypingSection.CONDITIONAL
|
|
102
98
|
)
|
|
103
|
-
file_import.
|
|
99
|
+
file_import.add_msrest_import(
|
|
100
|
+
self.code_model,
|
|
101
|
+
"..."
|
|
102
|
+
if (
|
|
103
|
+
not self.code_model.options["builders_visibility"] == "embedded"
|
|
104
|
+
and self.group_name
|
|
105
|
+
)
|
|
106
|
+
else "..",
|
|
107
|
+
MsrestImportType.Serializer,
|
|
108
|
+
TypingSection.REGULAR,
|
|
109
|
+
)
|
|
104
110
|
if (
|
|
105
111
|
self.overloads
|
|
106
112
|
and self.code_model.options["builders_visibility"] != "embedded"
|
|
@@ -136,23 +142,7 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
136
142
|
RequestBuilder.from_yaml(rb_yaml_data, code_model)
|
|
137
143
|
for rb_yaml_data in yaml_data.get("overloads", [])
|
|
138
144
|
]
|
|
139
|
-
abstract = False
|
|
140
145
|
parameter_list = cls.parameter_list_type()(yaml_data, code_model)
|
|
141
|
-
if (
|
|
142
|
-
code_model.options["version_tolerant"]
|
|
143
|
-
and parameter_list.has_body
|
|
144
|
-
and isinstance(
|
|
145
|
-
parameter_list.body_parameter, RequestBuilderMultipartBodyParameter
|
|
146
|
-
)
|
|
147
|
-
):
|
|
148
|
-
_LOGGER.warning(
|
|
149
|
-
'Not going to generate operation "%s" because it has multipart / urlencoded body parameters. '
|
|
150
|
-
"Multipart / urlencoded body parameters are not supported for version tolerant generation right now. "
|
|
151
|
-
'Please write your own custom operation in the "_patch.py" file '
|
|
152
|
-
"following https://aka.ms/azsdk/python/dpcodegen/python/customize",
|
|
153
|
-
name,
|
|
154
|
-
)
|
|
155
|
-
abstract = True
|
|
156
146
|
|
|
157
147
|
return cls(
|
|
158
148
|
yaml_data=yaml_data,
|
|
@@ -160,7 +150,6 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
|
|
|
160
150
|
name=name,
|
|
161
151
|
parameters=parameter_list,
|
|
162
152
|
overloads=overloads,
|
|
163
|
-
abstract=abstract,
|
|
164
153
|
)
|
|
165
154
|
|
|
166
155
|
|