@autorest/python 6.13.16 → 6.13.17
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/autorest/__init__.py +4 -12
- package/autorest/_utils.py +5 -20
- package/autorest/black/__init__.py +1 -3
- package/autorest/codegen/__init__.py +29 -96
- package/autorest/codegen/models/__init__.py +1 -3
- package/autorest/codegen/models/base.py +2 -6
- package/autorest/codegen/models/base_builder.py +2 -6
- package/autorest/codegen/models/client.py +24 -86
- package/autorest/codegen/models/code_model.py +13 -53
- package/autorest/codegen/models/combined_type.py +3 -9
- package/autorest/codegen/models/constant_type.py +4 -14
- package/autorest/codegen/models/credential_types.py +11 -35
- package/autorest/codegen/models/dictionary_type.py +4 -12
- package/autorest/codegen/models/enum_type.py +10 -31
- package/autorest/codegen/models/imports.py +15 -41
- package/autorest/codegen/models/list_type.py +7 -23
- package/autorest/codegen/models/lro_operation.py +6 -18
- package/autorest/codegen/models/lro_paging_operation.py +1 -3
- package/autorest/codegen/models/model_type.py +21 -73
- package/autorest/codegen/models/operation.py +41 -139
- package/autorest/codegen/models/operation_group.py +21 -60
- package/autorest/codegen/models/paging_operation.py +13 -43
- package/autorest/codegen/models/parameter.py +16 -54
- package/autorest/codegen/models/parameter_list.py +27 -103
- package/autorest/codegen/models/primitive_types.py +15 -49
- package/autorest/codegen/models/property.py +8 -28
- package/autorest/codegen/models/request_builder.py +11 -39
- package/autorest/codegen/models/request_builder_parameter.py +4 -13
- package/autorest/codegen/models/response.py +16 -57
- package/autorest/codegen/serializers/__init__.py +46 -150
- package/autorest/codegen/serializers/builder_serializer.py +113 -402
- package/autorest/codegen/serializers/client_serializer.py +25 -78
- package/autorest/codegen/serializers/enum_serializer.py +1 -3
- package/autorest/codegen/serializers/general_serializer.py +6 -22
- package/autorest/codegen/serializers/import_serializer.py +13 -40
- package/autorest/codegen/serializers/metadata_serializer.py +7 -21
- package/autorest/codegen/serializers/model_init_serializer.py +1 -5
- package/autorest/codegen/serializers/model_serializer.py +13 -51
- package/autorest/codegen/serializers/operation_groups_serializer.py +1 -3
- package/autorest/codegen/serializers/operations_init_serializer.py +2 -8
- package/autorest/codegen/serializers/parameter_serializer.py +8 -26
- package/autorest/codegen/serializers/request_builders_serializer.py +1 -3
- package/autorest/codegen/serializers/sample_serializer.py +13 -39
- package/autorest/codegen/serializers/test_serializer.py +10 -30
- package/autorest/codegen/serializers/types_serializer.py +1 -3
- package/autorest/jsonrpc/__init__.py +1 -3
- package/autorest/jsonrpc/server.py +3 -9
- package/autorest/jsonrpc/stdstream.py +4 -12
- package/autorest/m2r/__init__.py +2 -6
- package/autorest/m4reformatter/__init__.py +72 -237
- package/autorest/multiapi/__init__.py +4 -11
- package/autorest/multiapi/models/client.py +7 -21
- package/autorest/multiapi/models/code_model.py +9 -28
- package/autorest/multiapi/models/config.py +1 -3
- package/autorest/multiapi/models/global_parameters.py +6 -16
- package/autorest/multiapi/models/imports.py +5 -9
- package/autorest/multiapi/models/operation_mixin_group.py +5 -17
- package/autorest/multiapi/serializers/__init__.py +10 -31
- package/autorest/multiapi/serializers/import_serializer.py +8 -24
- package/autorest/multiapi/utils.py +2 -6
- package/autorest/multiclient/__init__.py +1 -3
- package/autorest/postprocess/__init__.py +9 -29
- package/autorest/postprocess/get_all.py +1 -3
- package/autorest/postprocess/venvtools.py +1 -3
- package/autorest/preprocess/__init__.py +40 -126
- package/install.py +2 -0
- package/package.json +1 -1
- package/prepare.py +3 -1
- package/requirements.txt +1 -1
- package/run_cadl.py +1 -3
- package/setup.py +25 -25
- package/start.py +2 -0
- package/venvtools.py +15 -10
|
@@ -17,9 +17,7 @@ if TYPE_CHECKING:
|
|
|
17
17
|
from .client import Client
|
|
18
18
|
from . import OperationType
|
|
19
19
|
|
|
20
|
-
LROResponseType = TypeVar(
|
|
21
|
-
"LROResponseType", bound=Union[LROResponse, LROPagingResponse]
|
|
22
|
-
)
|
|
20
|
+
LROResponseType = TypeVar("LROResponseType", bound=Union[LROResponse, LROPagingResponse])
|
|
23
21
|
|
|
24
22
|
|
|
25
23
|
class LROOperationBase(OperationBase[LROResponseType]):
|
|
@@ -55,9 +53,7 @@ class LROOperationBase(OperationBase[LROResponseType]):
|
|
|
55
53
|
@property
|
|
56
54
|
def initial_operation(self) -> "OperationType":
|
|
57
55
|
if not self._initial_operation:
|
|
58
|
-
raise ValueError(
|
|
59
|
-
"You need to first call client.link_lro_initial_operations before accessing"
|
|
60
|
-
)
|
|
56
|
+
raise ValueError("You need to first call client.link_lro_initial_operations before accessing")
|
|
61
57
|
return self._initial_operation
|
|
62
58
|
|
|
63
59
|
@initial_operation.setter
|
|
@@ -75,16 +71,12 @@ class LROOperationBase(OperationBase[LROResponseType]):
|
|
|
75
71
|
@property
|
|
76
72
|
def lro_response(self) -> Optional[LROResponseType]:
|
|
77
73
|
responses_with_bodies = [r for r in self.responses if r.type]
|
|
78
|
-
num_response_schemas = {
|
|
79
|
-
id(r.type.yaml_data) for r in responses_with_bodies if r.type
|
|
80
|
-
}
|
|
74
|
+
num_response_schemas = {id(r.type.yaml_data) for r in responses_with_bodies if r.type}
|
|
81
75
|
response = None
|
|
82
76
|
if len(num_response_schemas) > 1:
|
|
83
77
|
# choose the response that has a status code of 200
|
|
84
78
|
try:
|
|
85
|
-
response = next(
|
|
86
|
-
r for r in responses_with_bodies if 200 in r.status_codes
|
|
87
|
-
)
|
|
79
|
+
response = next(r for r in responses_with_bodies if 200 in r.status_codes)
|
|
88
80
|
except StopIteration as exc:
|
|
89
81
|
raise ValueError(
|
|
90
82
|
"Your swagger is invalid because you have multiple response schemas for LRO"
|
|
@@ -142,12 +134,8 @@ class LROOperationBase(OperationBase[LROResponseType]):
|
|
|
142
134
|
# used in the case if initial operation returns none
|
|
143
135
|
# but final call returns a model
|
|
144
136
|
relative_path = "..." if async_mode else ".."
|
|
145
|
-
file_import.add_submodule_import(
|
|
146
|
-
|
|
147
|
-
)
|
|
148
|
-
file_import.add_submodule_import(
|
|
149
|
-
"typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
150
|
-
)
|
|
137
|
+
file_import.add_submodule_import(f"{relative_path}_model_base", "_deserialize", ImportType.LOCAL)
|
|
138
|
+
file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
151
139
|
file_import.add_submodule_import("typing", "cast", ImportType.STDLIB)
|
|
152
140
|
return file_import
|
|
153
141
|
|
|
@@ -10,9 +10,7 @@ from .paging_operation import PagingOperationBase
|
|
|
10
10
|
from .response import LROPagingResponse, Response
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
class LROPagingOperation(
|
|
14
|
-
LROOperationBase[LROPagingResponse], PagingOperationBase[LROPagingResponse]
|
|
15
|
-
):
|
|
13
|
+
class LROPagingOperation(LROOperationBase[LROPagingResponse], PagingOperationBase[LROPagingResponse]):
|
|
16
14
|
@property
|
|
17
15
|
def success_status_codes(self):
|
|
18
16
|
"""The list of all successfull status code."""
|
|
@@ -30,13 +30,8 @@ def _get_properties(type: "ModelType", properties: List[Property]) -> List[Prope
|
|
|
30
30
|
|
|
31
31
|
# need to make sure that the properties we choose from our parent also don't contain
|
|
32
32
|
# any of our own properties
|
|
33
|
-
property_names = set(
|
|
34
|
-
|
|
35
|
-
+ [p.client_name for p in type.properties]
|
|
36
|
-
)
|
|
37
|
-
chosen_parent_properties = [
|
|
38
|
-
p for p in parent.properties if p.client_name not in property_names
|
|
39
|
-
]
|
|
33
|
+
property_names = set([p.client_name for p in properties] + [p.client_name for p in type.properties])
|
|
34
|
+
chosen_parent_properties = [p for p in parent.properties if p.client_name not in property_names]
|
|
40
35
|
properties = _get_properties(parent, chosen_parent_properties) + properties
|
|
41
36
|
return properties
|
|
42
37
|
|
|
@@ -70,17 +65,13 @@ class ModelType( # pylint: disable=abstract-method
|
|
|
70
65
|
self.properties = properties or []
|
|
71
66
|
self.parents = parents or []
|
|
72
67
|
self.discriminated_subtypes = discriminated_subtypes or {}
|
|
73
|
-
self.discriminator_value: Optional[str] = self.yaml_data.get(
|
|
74
|
-
"discriminatorValue"
|
|
75
|
-
)
|
|
68
|
+
self.discriminator_value: Optional[str] = self.yaml_data.get("discriminatorValue")
|
|
76
69
|
self._created_json_template_representation = False
|
|
77
70
|
self._got_polymorphic_subtypes = False
|
|
78
71
|
self.internal: bool = self.yaml_data.get("internal", False)
|
|
79
72
|
self.snake_case_name: str = self.yaml_data["snakeCaseName"]
|
|
80
73
|
self.page_result_model: bool = self.yaml_data.get("pageResultModel", False)
|
|
81
|
-
self.cross_language_definition_id: Optional[str] = self.yaml_data.get(
|
|
82
|
-
"crossLanguageDefinitionId"
|
|
83
|
-
)
|
|
74
|
+
self.cross_language_definition_id: Optional[str] = self.yaml_data.get("crossLanguageDefinitionId")
|
|
84
75
|
|
|
85
76
|
@property
|
|
86
77
|
def flattened_property(self) -> Optional[Property]:
|
|
@@ -151,11 +142,7 @@ class ModelType( # pylint: disable=abstract-method
|
|
|
151
142
|
if self.discriminated_subtypes:
|
|
152
143
|
# we will instead print the discriminated subtypes
|
|
153
144
|
self._created_json_template_representation = False
|
|
154
|
-
return
|
|
155
|
-
f'"{self.snake_case_name}"'
|
|
156
|
-
if self.code_model.for_test
|
|
157
|
-
else self.snake_case_name
|
|
158
|
-
)
|
|
145
|
+
return f'"{self.snake_case_name}"' if self.code_model.for_test else self.snake_case_name
|
|
159
146
|
|
|
160
147
|
# don't add additional properties, because there's not really a concept of
|
|
161
148
|
# additional properties in the template
|
|
@@ -166,22 +153,16 @@ class ModelType( # pylint: disable=abstract-method
|
|
|
166
153
|
description=description,
|
|
167
154
|
)
|
|
168
155
|
for prop in [
|
|
169
|
-
p
|
|
170
|
-
for p in self.properties
|
|
171
|
-
if not (p.is_discriminator or p.client_name == "additional_properties")
|
|
156
|
+
p for p in self.properties if not (p.is_discriminator or p.client_name == "additional_properties")
|
|
172
157
|
]
|
|
173
158
|
}
|
|
174
159
|
if self.discriminator and self.discriminator_value:
|
|
175
|
-
representation[f'"{self.discriminator.wire_name}"'] =
|
|
176
|
-
f'"{self.discriminator_value}"'
|
|
177
|
-
)
|
|
160
|
+
representation[f'"{self.discriminator.wire_name}"'] = f'"{self.discriminator_value}"'
|
|
178
161
|
|
|
179
162
|
# once we've finished, we want to reset created_json_template_representation to false
|
|
180
163
|
# so we can call it again
|
|
181
164
|
self._created_json_template_representation = False
|
|
182
|
-
optional_keys = [
|
|
183
|
-
f'"{p.wire_name}"' for p in self.properties if getattr(p, "optional", False)
|
|
184
|
-
]
|
|
165
|
+
optional_keys = [f'"{p.wire_name}"' for p in self.properties if getattr(p, "optional", False)]
|
|
185
166
|
return OrderedDict(
|
|
186
167
|
sorted(
|
|
187
168
|
representation.items(),
|
|
@@ -190,16 +171,11 @@ class ModelType( # pylint: disable=abstract-method
|
|
|
190
171
|
)
|
|
191
172
|
|
|
192
173
|
def get_polymorphic_subtypes(self, polymorphic_subtypes: List["ModelType"]) -> None:
|
|
193
|
-
is_polymorphic_subtype =
|
|
194
|
-
self.discriminator_value and not self.discriminated_subtypes
|
|
195
|
-
)
|
|
174
|
+
is_polymorphic_subtype = self.discriminator_value and not self.discriminated_subtypes
|
|
196
175
|
if self._got_polymorphic_subtypes:
|
|
197
176
|
return
|
|
198
177
|
self._got_polymorphic_subtypes = True
|
|
199
|
-
if (
|
|
200
|
-
self.name not in (m.name for m in polymorphic_subtypes)
|
|
201
|
-
and is_polymorphic_subtype
|
|
202
|
-
):
|
|
178
|
+
if self.name not in (m.name for m in polymorphic_subtypes) and is_polymorphic_subtype:
|
|
203
179
|
polymorphic_subtypes.append(self)
|
|
204
180
|
for discriminated_subtype in self.discriminated_subtypes.values():
|
|
205
181
|
discriminated_subtype.get_polymorphic_subtypes(polymorphic_subtypes)
|
|
@@ -208,26 +184,17 @@ class ModelType( # pylint: disable=abstract-method
|
|
|
208
184
|
self._got_polymorphic_subtypes = False
|
|
209
185
|
|
|
210
186
|
@classmethod
|
|
211
|
-
def from_yaml(
|
|
212
|
-
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
213
|
-
) -> "ModelType":
|
|
187
|
+
def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "ModelType":
|
|
214
188
|
raise ValueError(
|
|
215
189
|
"You shouldn't call from_yaml for ModelType to avoid recursion. "
|
|
216
190
|
"Please initial a blank ModelType, then call .fill_instance_from_yaml on the created type."
|
|
217
191
|
)
|
|
218
192
|
|
|
219
|
-
def fill_instance_from_yaml(
|
|
220
|
-
self, yaml_data: Dict[str, Any], code_model: "CodeModel"
|
|
221
|
-
) -> None:
|
|
193
|
+
def fill_instance_from_yaml(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
|
|
222
194
|
from . import build_type
|
|
223
195
|
|
|
224
|
-
self.parents = [
|
|
225
|
-
|
|
226
|
-
for bm in yaml_data.get("parents", [])
|
|
227
|
-
]
|
|
228
|
-
properties = [
|
|
229
|
-
Property.from_yaml(p, code_model) for p in yaml_data["properties"]
|
|
230
|
-
]
|
|
196
|
+
self.parents = [cast(ModelType, build_type(bm, code_model)) for bm in yaml_data.get("parents", [])]
|
|
197
|
+
properties = [Property.from_yaml(p, code_model) for p in yaml_data["properties"]]
|
|
231
198
|
self.properties = _get_properties(self, properties)
|
|
232
199
|
# checking to see if this is a polymorphic class
|
|
233
200
|
self.discriminated_subtypes = {
|
|
@@ -237,10 +204,7 @@ class ModelType( # pylint: disable=abstract-method
|
|
|
237
204
|
|
|
238
205
|
@property
|
|
239
206
|
def has_readonly_or_constant_property(self) -> bool:
|
|
240
|
-
return any(
|
|
241
|
-
x.readonly or x.constant or x.visibility == ["read"]
|
|
242
|
-
for x in self.properties
|
|
243
|
-
)
|
|
207
|
+
return any(x.readonly or x.constant or x.visibility == ["read"] for x in self.properties)
|
|
244
208
|
|
|
245
209
|
@property
|
|
246
210
|
def discriminator(self) -> Optional[Property]:
|
|
@@ -255,9 +219,7 @@ class ModelType( # pylint: disable=abstract-method
|
|
|
255
219
|
return next(
|
|
256
220
|
p
|
|
257
221
|
for p in self.properties
|
|
258
|
-
if p.is_discriminator
|
|
259
|
-
and isinstance(p.type, ConstantType)
|
|
260
|
-
and p.type.value == self.discriminator_value
|
|
222
|
+
if p.is_discriminator and isinstance(p.type, ConstantType) and p.type.value == self.discriminator_value
|
|
261
223
|
)
|
|
262
224
|
except StopIteration:
|
|
263
225
|
return None
|
|
@@ -301,14 +263,10 @@ class JSONModelType(ModelType):
|
|
|
301
263
|
|
|
302
264
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
303
265
|
file_import = FileImport(self.code_model)
|
|
304
|
-
file_import.add_submodule_import(
|
|
305
|
-
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
306
|
-
)
|
|
266
|
+
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
307
267
|
file_import.define_mutable_mapping_type()
|
|
308
268
|
if self.is_xml:
|
|
309
|
-
file_import.add_submodule_import(
|
|
310
|
-
"xml.etree", "ElementTree", ImportType.STDLIB, alias="ET"
|
|
311
|
-
)
|
|
269
|
+
file_import.add_submodule_import("xml.etree", "ElementTree", ImportType.STDLIB, alias="ET")
|
|
312
270
|
return file_import
|
|
313
271
|
|
|
314
272
|
|
|
@@ -341,22 +299,14 @@ class GeneratedModelType(ModelType): # pylint: disable=abstract-method
|
|
|
341
299
|
"models",
|
|
342
300
|
ImportType.LOCAL,
|
|
343
301
|
alias="_models",
|
|
344
|
-
typing_section=(
|
|
345
|
-
TypingSection.TYPING
|
|
346
|
-
if kwargs.get("model_typing")
|
|
347
|
-
else TypingSection.REGULAR
|
|
348
|
-
),
|
|
302
|
+
typing_section=(TypingSection.TYPING if kwargs.get("model_typing") else TypingSection.REGULAR),
|
|
349
303
|
)
|
|
350
304
|
if self.is_form_data:
|
|
351
305
|
file_import.add_submodule_import(
|
|
352
306
|
relative_path,
|
|
353
307
|
"_model_base",
|
|
354
308
|
ImportType.LOCAL,
|
|
355
|
-
typing_section=(
|
|
356
|
-
TypingSection.TYPING
|
|
357
|
-
if kwargs.get("model_typing")
|
|
358
|
-
else TypingSection.REGULAR
|
|
359
|
-
),
|
|
309
|
+
typing_section=(TypingSection.TYPING if kwargs.get("model_typing") else TypingSection.REGULAR),
|
|
360
310
|
)
|
|
361
311
|
return file_import
|
|
362
312
|
|
|
@@ -374,9 +324,7 @@ class MsrestModelType(GeneratedModelType):
|
|
|
374
324
|
|
|
375
325
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
376
326
|
file_import = super().imports(**kwargs)
|
|
377
|
-
file_import.add_submodule_import(
|
|
378
|
-
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
379
|
-
)
|
|
327
|
+
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
380
328
|
return file_import
|
|
381
329
|
|
|
382
330
|
|
|
@@ -83,17 +83,13 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
83
83
|
self.request_builder = request_builder
|
|
84
84
|
self.deprecated = False
|
|
85
85
|
self.exceptions = exceptions
|
|
86
|
-
self.is_lro_initial_operation: bool = self.yaml_data.get(
|
|
87
|
-
"isLroInitialOperation", False
|
|
88
|
-
)
|
|
86
|
+
self.is_lro_initial_operation: bool = self.yaml_data.get("isLroInitialOperation", False)
|
|
89
87
|
self.include_documentation: bool = not self.is_lro_initial_operation
|
|
90
88
|
self.internal: bool = self.yaml_data.get("internal", False)
|
|
91
89
|
if self.internal:
|
|
92
90
|
self.name = "_" + self.name
|
|
93
91
|
self.has_etag: bool = self.yaml_data.get("hasEtag", False)
|
|
94
|
-
self.cross_language_definition_id: Optional[str] = self.yaml_data.get(
|
|
95
|
-
"crossLanguageDefinitionId"
|
|
96
|
-
)
|
|
92
|
+
self.cross_language_definition_id: Optional[str] = self.yaml_data.get("crossLanguageDefinitionId")
|
|
97
93
|
|
|
98
94
|
@property
|
|
99
95
|
def has_form_data_body(self):
|
|
@@ -118,15 +114,10 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
118
114
|
return successful_response_with_body and successful_response_without_body
|
|
119
115
|
|
|
120
116
|
def response_type_annotation(self, **kwargs) -> str:
|
|
121
|
-
if (
|
|
122
|
-
self.code_model.options["head_as_boolean"]
|
|
123
|
-
and self.request_builder.method.lower() == "head"
|
|
124
|
-
):
|
|
117
|
+
if self.code_model.options["head_as_boolean"] and self.request_builder.method.lower() == "head":
|
|
125
118
|
return "bool"
|
|
126
119
|
response_type_annotations: OrderedSet[str] = {
|
|
127
|
-
response.type_annotation(**kwargs): None
|
|
128
|
-
for response in self.responses
|
|
129
|
-
if response.type
|
|
120
|
+
response.type_annotation(**kwargs): None for response in self.responses if response.type
|
|
130
121
|
}
|
|
131
122
|
response_str = ", ".join(response_type_annotations.keys())
|
|
132
123
|
if len(response_type_annotations) > 1:
|
|
@@ -144,9 +135,7 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
144
135
|
# doesn't matter if it's async or not
|
|
145
136
|
retval = add_to_pylint_disable(retval, "inconsistent-return-statements")
|
|
146
137
|
try:
|
|
147
|
-
if any(is_internal(r.type) for r in self.responses) or is_internal(
|
|
148
|
-
self.parameters.body_parameter.type
|
|
149
|
-
):
|
|
138
|
+
if any(is_internal(r.type) for r in self.responses) or is_internal(self.parameters.body_parameter.type):
|
|
150
139
|
retval = add_to_pylint_disable(retval, "protected-access")
|
|
151
140
|
except ValueError:
|
|
152
141
|
pass
|
|
@@ -155,24 +144,17 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
155
144
|
return retval
|
|
156
145
|
|
|
157
146
|
def cls_type_annotation(self, *, async_mode: bool) -> str:
|
|
158
|
-
if (
|
|
159
|
-
self.request_builder.method.lower() == "head"
|
|
160
|
-
and self.code_model.options["head_as_boolean"]
|
|
161
|
-
):
|
|
147
|
+
if self.request_builder.method.lower() == "head" and self.code_model.options["head_as_boolean"]:
|
|
162
148
|
return "ClsType[None]"
|
|
163
149
|
return f"ClsType[{self.response_type_annotation(async_mode=async_mode)}]"
|
|
164
150
|
|
|
165
151
|
def _response_docstring_helper(self, attr_name: str, **kwargs: Any) -> str:
|
|
166
152
|
responses_with_body = [r for r in self.responses if r.type]
|
|
167
|
-
if (
|
|
168
|
-
self.request_builder.method.lower() == "head"
|
|
169
|
-
and self.code_model.options["head_as_boolean"]
|
|
170
|
-
):
|
|
153
|
+
if self.request_builder.method.lower() == "head" and self.code_model.options["head_as_boolean"]:
|
|
171
154
|
return "bool"
|
|
172
155
|
if responses_with_body:
|
|
173
156
|
response_docstring_values: OrderedSet[str] = {
|
|
174
|
-
getattr(response, attr_name)(**kwargs): None
|
|
175
|
-
for response in responses_with_body
|
|
157
|
+
getattr(response, attr_name)(**kwargs): None for response in responses_with_body
|
|
176
158
|
}
|
|
177
159
|
retval = " or ".join(response_docstring_values.keys())
|
|
178
160
|
if self.has_optional_return_type:
|
|
@@ -210,9 +192,7 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
210
192
|
|
|
211
193
|
@property
|
|
212
194
|
def default_error_deserialization(self) -> Optional[str]:
|
|
213
|
-
default_exceptions = [
|
|
214
|
-
e for e in self.exceptions if "default" in e.status_codes and e.type
|
|
215
|
-
]
|
|
195
|
+
default_exceptions = [e for e in self.exceptions if "default" in e.status_codes and e.type]
|
|
216
196
|
if not default_exceptions:
|
|
217
197
|
return None
|
|
218
198
|
excep_schema = default_exceptions[0].type
|
|
@@ -228,29 +208,15 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
228
208
|
@property
|
|
229
209
|
def non_default_error_status_codes(self) -> List[Union[str, int]]:
|
|
230
210
|
"""Actually returns all of the status codes from exceptions (besides default)"""
|
|
231
|
-
return list(
|
|
232
|
-
chain.from_iterable(
|
|
233
|
-
[error.status_codes for error in self.non_default_errors]
|
|
234
|
-
)
|
|
235
|
-
)
|
|
211
|
+
return list(chain.from_iterable([error.status_codes for error in self.non_default_errors]))
|
|
236
212
|
|
|
237
|
-
def _imports_shared(
|
|
238
|
-
self, async_mode: bool, **kwargs: Any # pylint: disable=unused-argument
|
|
239
|
-
) -> FileImport:
|
|
213
|
+
def _imports_shared(self, async_mode: bool, **kwargs: Any) -> FileImport: # pylint: disable=unused-argument
|
|
240
214
|
file_import = FileImport(self.code_model)
|
|
241
|
-
file_import.add_submodule_import(
|
|
242
|
-
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
243
|
-
)
|
|
215
|
+
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
244
216
|
|
|
245
|
-
response_types = [
|
|
246
|
-
r.type_annotation(async_mode=async_mode, operation=self)
|
|
247
|
-
for r in self.responses
|
|
248
|
-
if r.type
|
|
249
|
-
]
|
|
217
|
+
response_types = [r.type_annotation(async_mode=async_mode, operation=self) for r in self.responses if r.type]
|
|
250
218
|
if len(set(response_types)) > 1:
|
|
251
|
-
file_import.add_submodule_import(
|
|
252
|
-
"typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
253
|
-
)
|
|
219
|
+
file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
254
220
|
if self.added_on:
|
|
255
221
|
file_import.add_submodule_import(
|
|
256
222
|
f"{'.' if async_mode else ''}.._validation",
|
|
@@ -272,18 +238,10 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
272
238
|
)
|
|
273
239
|
)
|
|
274
240
|
for response in self.responses:
|
|
275
|
-
file_import.merge(
|
|
276
|
-
response.imports_for_multiapi(
|
|
277
|
-
async_mode=async_mode, operation=self, **kwargs
|
|
278
|
-
)
|
|
279
|
-
)
|
|
241
|
+
file_import.merge(response.imports_for_multiapi(async_mode=async_mode, operation=self, **kwargs))
|
|
280
242
|
if self.code_model.options["models_mode"]:
|
|
281
243
|
for exception in self.exceptions:
|
|
282
|
-
file_import.merge(
|
|
283
|
-
exception.imports_for_multiapi(
|
|
284
|
-
async_mode=async_mode, operation=self, **kwargs
|
|
285
|
-
)
|
|
286
|
-
)
|
|
244
|
+
file_import.merge(exception.imports_for_multiapi(async_mode=async_mode, operation=self, **kwargs))
|
|
287
245
|
return file_import
|
|
288
246
|
|
|
289
247
|
@staticmethod
|
|
@@ -298,9 +256,7 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
298
256
|
location: ParameterLocation,
|
|
299
257
|
) -> bool:
|
|
300
258
|
return any(
|
|
301
|
-
(kwarg.client_default_value or kwarg.optional)
|
|
302
|
-
and kwarg.location == location
|
|
303
|
-
for kwarg in kwargs_to_pop
|
|
259
|
+
(kwarg.client_default_value or kwarg.optional) and kwarg.location == location for kwarg in kwargs_to_pop
|
|
304
260
|
)
|
|
305
261
|
|
|
306
262
|
@property
|
|
@@ -356,17 +312,13 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
356
312
|
)
|
|
357
313
|
)
|
|
358
314
|
for response in self.responses:
|
|
359
|
-
file_import.merge(
|
|
360
|
-
response.imports(async_mode=async_mode, operation=self, **kwargs)
|
|
361
|
-
)
|
|
315
|
+
file_import.merge(response.imports(async_mode=async_mode, operation=self, **kwargs))
|
|
362
316
|
if self.code_model.options["models_mode"]:
|
|
363
317
|
for exception in self.exceptions:
|
|
364
318
|
file_import.merge(exception.imports(async_mode=async_mode, **kwargs))
|
|
365
319
|
|
|
366
320
|
if self.parameters.has_body and self.parameters.body_parameter.flattened:
|
|
367
|
-
file_import.merge(
|
|
368
|
-
self.parameters.body_parameter.type.imports(operation=self, **kwargs)
|
|
369
|
-
)
|
|
321
|
+
file_import.merge(self.parameters.body_parameter.type.imports(operation=self, **kwargs))
|
|
370
322
|
if not async_mode:
|
|
371
323
|
for param in self.parameters.headers:
|
|
372
324
|
if param.wire_name.lower() == "repeatability-request-id":
|
|
@@ -386,9 +338,7 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
386
338
|
for error in errors:
|
|
387
339
|
file_import.add_submodule_import("exceptions", error, ImportType.SDKCORE)
|
|
388
340
|
if self.code_model.options["azure_arm"]:
|
|
389
|
-
file_import.add_submodule_import(
|
|
390
|
-
"azure.mgmt.core.exceptions", "ARMErrorFormat", ImportType.SDKCORE
|
|
391
|
-
)
|
|
341
|
+
file_import.add_submodule_import("azure.mgmt.core.exceptions", "ARMErrorFormat", ImportType.SDKCORE)
|
|
392
342
|
file_import.add_submodule_import(
|
|
393
343
|
"typing",
|
|
394
344
|
"Type",
|
|
@@ -417,9 +367,7 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
417
367
|
|
|
418
368
|
relative_path = "..." if async_mode else ".."
|
|
419
369
|
if self.code_model.need_request_converter:
|
|
420
|
-
file_import.add_submodule_import(
|
|
421
|
-
f"{relative_path}_vendor", "_convert_request", ImportType.LOCAL
|
|
422
|
-
)
|
|
370
|
+
file_import.add_submodule_import(f"{relative_path}_vendor", "_convert_request", ImportType.LOCAL)
|
|
423
371
|
if self.has_etag:
|
|
424
372
|
file_import.add_submodule_import(
|
|
425
373
|
"exceptions",
|
|
@@ -427,12 +375,8 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
427
375
|
ImportType.SDKCORE,
|
|
428
376
|
)
|
|
429
377
|
if not async_mode:
|
|
430
|
-
file_import.add_submodule_import(
|
|
431
|
-
|
|
432
|
-
)
|
|
433
|
-
file_import.add_submodule_import(
|
|
434
|
-
f"{relative_path}_vendor", "prep_if_none_match", ImportType.LOCAL
|
|
435
|
-
)
|
|
378
|
+
file_import.add_submodule_import(f"{relative_path}_vendor", "prep_if_match", ImportType.LOCAL)
|
|
379
|
+
file_import.add_submodule_import(f"{relative_path}_vendor", "prep_if_none_match", ImportType.LOCAL)
|
|
436
380
|
if self.code_model.need_request_converter:
|
|
437
381
|
if async_mode:
|
|
438
382
|
file_import.add_submodule_import(
|
|
@@ -459,10 +403,7 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
459
403
|
"HttpResponse",
|
|
460
404
|
ImportType.SDKCORE,
|
|
461
405
|
)
|
|
462
|
-
if
|
|
463
|
-
self.code_model.options["builders_visibility"] == "embedded"
|
|
464
|
-
and not async_mode
|
|
465
|
-
):
|
|
406
|
+
if self.code_model.options["builders_visibility"] == "embedded" and not async_mode:
|
|
466
407
|
file_import.merge(self.request_builder.imports())
|
|
467
408
|
file_import.add_submodule_import(
|
|
468
409
|
f"{'' if self.code_model.is_azure_flavor else 'runtime.'}pipeline",
|
|
@@ -470,51 +411,33 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
470
411
|
ImportType.SDKCORE,
|
|
471
412
|
)
|
|
472
413
|
file_import.add_submodule_import("rest", "HttpRequest", ImportType.SDKCORE)
|
|
473
|
-
file_import.add_submodule_import(
|
|
474
|
-
|
|
475
|
-
)
|
|
476
|
-
file_import.add_submodule_import(
|
|
477
|
-
"typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
478
|
-
)
|
|
479
|
-
file_import.add_submodule_import(
|
|
480
|
-
"typing", "Dict", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
481
|
-
)
|
|
482
|
-
file_import.add_submodule_import(
|
|
483
|
-
"typing", "TypeVar", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
484
|
-
)
|
|
414
|
+
file_import.add_submodule_import("typing", "Callable", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
415
|
+
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
416
|
+
file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
417
|
+
file_import.add_submodule_import("typing", "TypeVar", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
485
418
|
if self.code_model.options["tracing"] and self.want_tracing and not async_mode:
|
|
486
419
|
file_import.add_submodule_import(
|
|
487
420
|
"azure.core.tracing.decorator",
|
|
488
421
|
"distributed_trace",
|
|
489
422
|
ImportType.SDKCORE,
|
|
490
423
|
)
|
|
491
|
-
file_import.merge(
|
|
492
|
-
self.get_request_builder_import(self.request_builder, async_mode)
|
|
493
|
-
)
|
|
424
|
+
file_import.merge(self.get_request_builder_import(self.request_builder, async_mode))
|
|
494
425
|
if self.overloads:
|
|
495
426
|
file_import.add_submodule_import("typing", "overload", ImportType.STDLIB)
|
|
496
427
|
if self.non_default_errors and self.code_model.options["models_mode"] == "dpg":
|
|
497
|
-
file_import.add_submodule_import(
|
|
498
|
-
f"{relative_path}_model_base", "_deserialize", ImportType.LOCAL
|
|
499
|
-
)
|
|
428
|
+
file_import.add_submodule_import(f"{relative_path}_model_base", "_deserialize", ImportType.LOCAL)
|
|
500
429
|
return file_import
|
|
501
430
|
|
|
502
|
-
def get_response_from_status(
|
|
503
|
-
self, status_code: Optional[Union[str, int]]
|
|
504
|
-
) -> ResponseType:
|
|
431
|
+
def get_response_from_status(self, status_code: Optional[Union[str, int]]) -> ResponseType:
|
|
505
432
|
try:
|
|
506
433
|
return next(r for r in self.responses if status_code in r.status_codes)
|
|
507
434
|
except StopIteration as exc:
|
|
508
|
-
raise ValueError(
|
|
509
|
-
f"Incorrect status code {status_code}, operation {self.name}"
|
|
510
|
-
) from exc
|
|
435
|
+
raise ValueError(f"Incorrect status code {status_code}, operation {self.name}") from exc
|
|
511
436
|
|
|
512
437
|
@property
|
|
513
438
|
def success_status_codes(self) -> Sequence[Union[str, int]]:
|
|
514
439
|
"""The list of all successfull status code."""
|
|
515
|
-
return sorted(
|
|
516
|
-
[code for response in self.responses for code in response.status_codes]
|
|
517
|
-
)
|
|
440
|
+
return sorted([code for response in self.responses for code in response.status_codes])
|
|
518
441
|
|
|
519
442
|
@property
|
|
520
443
|
def filename(self) -> str:
|
|
@@ -523,10 +446,7 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
523
446
|
# in a mixin
|
|
524
447
|
basename = self.code_model.clients[0].legacy_filename
|
|
525
448
|
|
|
526
|
-
if
|
|
527
|
-
basename == "operations"
|
|
528
|
-
or self.code_model.options["combine_operation_files"]
|
|
529
|
-
):
|
|
449
|
+
if basename == "operations" or self.code_model.options["combine_operation_files"]:
|
|
530
450
|
return "_operations"
|
|
531
451
|
return f"_{basename}_operations"
|
|
532
452
|
|
|
@@ -547,18 +467,10 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
|
|
|
547
467
|
):
|
|
548
468
|
name = yaml_data["name"]
|
|
549
469
|
request_builder = cls.get_request_builder(yaml_data, client)
|
|
550
|
-
responses = [
|
|
551
|
-
|
|
552
|
-
for r in yaml_data["responses"]
|
|
553
|
-
]
|
|
554
|
-
exceptions = [
|
|
555
|
-
Response.from_yaml(e, code_model) for e in yaml_data["exceptions"]
|
|
556
|
-
]
|
|
470
|
+
responses = [cast(ResponseType, get_response(r, code_model)) for r in yaml_data["responses"]]
|
|
471
|
+
exceptions = [Response.from_yaml(e, code_model) for e in yaml_data["exceptions"]]
|
|
557
472
|
parameter_list = ParameterList.from_yaml(yaml_data, code_model)
|
|
558
|
-
overloads = [
|
|
559
|
-
cls.from_yaml(overload, code_model, client)
|
|
560
|
-
for overload in yaml_data.get("overloads", [])
|
|
561
|
-
]
|
|
473
|
+
overloads = [cls.from_yaml(overload, code_model, client) for overload in yaml_data.get("overloads", [])]
|
|
562
474
|
|
|
563
475
|
return cls(
|
|
564
476
|
yaml_data=yaml_data,
|
|
@@ -584,11 +496,7 @@ class Operation(OperationBase[Response]):
|
|
|
584
496
|
"distributed_trace_async",
|
|
585
497
|
ImportType.SDKCORE,
|
|
586
498
|
)
|
|
587
|
-
if
|
|
588
|
-
self.has_response_body
|
|
589
|
-
and not self.has_optional_return_type
|
|
590
|
-
and not self.code_model.options["models_mode"]
|
|
591
|
-
):
|
|
499
|
+
if self.has_response_body and not self.has_optional_return_type and not self.code_model.options["models_mode"]:
|
|
592
500
|
file_import.add_submodule_import("typing", "cast", ImportType.STDLIB)
|
|
593
501
|
relative_path = "..." if async_mode else ".."
|
|
594
502
|
if self.code_model.options["models_mode"] == "dpg":
|
|
@@ -600,19 +508,13 @@ class Operation(OperationBase[Response]):
|
|
|
600
508
|
ImportType.LOCAL,
|
|
601
509
|
)
|
|
602
510
|
file_import.add_import("json", ImportType.STDLIB)
|
|
603
|
-
if self.default_error_deserialization or any(
|
|
604
|
-
|
|
605
|
-
):
|
|
606
|
-
file_import.add_submodule_import(
|
|
607
|
-
f"{relative_path}_model_base", "_deserialize", ImportType.LOCAL
|
|
608
|
-
)
|
|
511
|
+
if self.default_error_deserialization or any(r.type for r in self.responses):
|
|
512
|
+
file_import.add_submodule_import(f"{relative_path}_model_base", "_deserialize", ImportType.LOCAL)
|
|
609
513
|
|
|
610
514
|
return file_import
|
|
611
515
|
|
|
612
516
|
|
|
613
|
-
def get_operation(
|
|
614
|
-
yaml_data: Dict[str, Any], code_model: "CodeModel", client: "Client"
|
|
615
|
-
) -> "OperationType":
|
|
517
|
+
def get_operation(yaml_data: Dict[str, Any], code_model: "CodeModel", client: "Client") -> "OperationType":
|
|
616
518
|
if yaml_data["discriminator"] == "lropaging":
|
|
617
519
|
from .lro_paging_operation import LROPagingOperation as OperationCls
|
|
618
520
|
elif yaml_data["discriminator"] == "lro":
|