@autorest/python 6.9.5 → 6.9.7
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/codegen/__init__.py +2 -4
- package/autorest/codegen/models/base.py +2 -5
- package/autorest/codegen/models/client.py +12 -8
- package/autorest/codegen/models/code_model.py +5 -1
- package/autorest/codegen/models/combined_type.py +1 -1
- package/autorest/codegen/models/constant_type.py +1 -1
- package/autorest/codegen/models/credential_types.py +21 -11
- package/autorest/codegen/models/dictionary_type.py +1 -1
- package/autorest/codegen/models/enum_type.py +2 -2
- package/autorest/codegen/models/imports.py +18 -69
- package/autorest/codegen/models/list_type.py +1 -1
- package/autorest/codegen/models/model_type.py +1 -1
- package/autorest/codegen/models/operation.py +11 -15
- package/autorest/codegen/models/operation_group.py +2 -2
- package/autorest/codegen/models/paging_operation.py +4 -4
- package/autorest/codegen/models/parameter.py +1 -1
- package/autorest/codegen/models/primitive_types.py +12 -16
- package/autorest/codegen/models/property.py +1 -1
- package/autorest/codegen/models/request_builder.py +4 -4
- package/autorest/codegen/models/response.py +32 -10
- package/autorest/codegen/serializers/builder_serializer.py +15 -11
- package/autorest/codegen/serializers/client_serializer.py +5 -8
- package/autorest/codegen/serializers/enum_serializer.py +2 -1
- package/autorest/codegen/serializers/general_serializer.py +9 -10
- package/autorest/codegen/serializers/model_serializer.py +2 -2
- package/autorest/codegen/serializers/operation_groups_serializer.py +2 -1
- package/autorest/codegen/serializers/patch_serializer.py +2 -2
- package/autorest/codegen/serializers/request_builders_serializer.py +1 -1
- package/autorest/codegen/serializers/sample_serializer.py +17 -13
- package/autorest/codegen/serializers/types_serializer.py +1 -1
- package/autorest/codegen/templates/client.py.jinja2 +1 -1
- package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/model_base.py.jinja2 +12 -9
- package/autorest/codegen/templates/model_dpg.py.jinja2 +1 -1
- package/autorest/codegen/templates/model_msrest.py.jinja2 +1 -1
- package/autorest/codegen/templates/packaging_templates/LICENSE.jinja2 +1 -1
- package/autorest/codegen/templates/packaging_templates/README.md.jinja2 +1 -1
- package/autorest/codegen/templates/packaging_templates/setup.py.jinja2 +4 -4
- package/autorest/codegen/templates/patch.py.jinja2 +1 -1
- package/autorest/codegen/templates/serialization.py.jinja2 +4 -7
- package/autorest/multiapi/models/code_model.py +2 -0
- package/autorest/multiapi/serializers/__init__.py +1 -2
- package/autorest/preprocess/__init__.py +27 -25
- package/package.json +1 -1
|
@@ -48,10 +48,8 @@ class OptionsRetriever:
|
|
|
48
48
|
return self.options.get(key, self.OPTIONS_TO_DEFAULT.get(key))
|
|
49
49
|
|
|
50
50
|
@property
|
|
51
|
-
def company_name(self) ->
|
|
52
|
-
return self.options.get(
|
|
53
|
-
"company-name", "Microsoft" if not self.unbranded else ""
|
|
54
|
-
)
|
|
51
|
+
def company_name(self) -> str:
|
|
52
|
+
return self.options.get("company-name", "" if self.unbranded else "Microsoft")
|
|
55
53
|
|
|
56
54
|
@property
|
|
57
55
|
def license_header(self) -> str:
|
|
@@ -31,9 +31,6 @@ class BaseModel:
|
|
|
31
31
|
def __repr__(self):
|
|
32
32
|
return f"<{self.__class__.__name__}>"
|
|
33
33
|
|
|
34
|
-
def init_file_import(self) -> FileImport:
|
|
35
|
-
return FileImport(self.code_model)
|
|
36
|
-
|
|
37
34
|
|
|
38
35
|
class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
39
36
|
"""This is the base class for all types.
|
|
@@ -56,13 +53,13 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
|
|
|
56
53
|
return cls(yaml_data=yaml_data, code_model=code_model)
|
|
57
54
|
|
|
58
55
|
def imports(self, **kwargs) -> FileImport: # pylint: disable=unused-argument
|
|
59
|
-
return self.
|
|
56
|
+
return FileImport(self.code_model)
|
|
60
57
|
|
|
61
58
|
def imports_for_multiapi(self, **kwargs: Any) -> FileImport:
|
|
62
59
|
return self.imports(**kwargs)
|
|
63
60
|
|
|
64
61
|
def imports_for_sample(self) -> FileImport:
|
|
65
|
-
return self.
|
|
62
|
+
return self.imports()
|
|
66
63
|
|
|
67
64
|
@staticmethod
|
|
68
65
|
def serialize_sample_value(value: Any) -> str:
|
|
@@ -195,7 +195,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
195
195
|
raise KeyError(f"No operation with id {operation_id} found.") from exc
|
|
196
196
|
|
|
197
197
|
def _imports_shared(self, async_mode: bool) -> FileImport:
|
|
198
|
-
file_import = self.
|
|
198
|
+
file_import = FileImport(self.code_model)
|
|
199
199
|
file_import.add_submodule_import(
|
|
200
200
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
201
201
|
)
|
|
@@ -205,7 +205,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
205
205
|
)
|
|
206
206
|
else:
|
|
207
207
|
file_import.add_submodule_import(
|
|
208
|
-
|
|
208
|
+
"runtime" if self.code_model.options["unbranded"] else "",
|
|
209
209
|
self.pipeline_class(async_mode),
|
|
210
210
|
ImportType.SDKCORE,
|
|
211
211
|
)
|
|
@@ -231,7 +231,9 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
231
231
|
typing_section=TypingSection.REGULAR,
|
|
232
232
|
)
|
|
233
233
|
file_import.add_submodule_import(
|
|
234
|
-
|
|
234
|
+
"runtime" if self.code_model.options["unbranded"] else "pipeline",
|
|
235
|
+
"policies",
|
|
236
|
+
ImportType.SDKCORE,
|
|
235
237
|
)
|
|
236
238
|
if self.code_model.options["azure_arm"]:
|
|
237
239
|
async_prefix = "Async" if async_mode else ""
|
|
@@ -300,20 +302,20 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
300
302
|
if async_mode:
|
|
301
303
|
file_import.add_submodule_import("typing", "Awaitable", ImportType.STDLIB)
|
|
302
304
|
file_import.add_submodule_import(
|
|
303
|
-
|
|
305
|
+
"rest",
|
|
304
306
|
"AsyncHttpResponse",
|
|
305
307
|
ImportType.SDKCORE,
|
|
306
308
|
TypingSection.CONDITIONAL,
|
|
307
309
|
)
|
|
308
310
|
else:
|
|
309
311
|
file_import.add_submodule_import(
|
|
310
|
-
|
|
312
|
+
"rest",
|
|
311
313
|
"HttpResponse",
|
|
312
314
|
ImportType.SDKCORE,
|
|
313
315
|
TypingSection.CONDITIONAL,
|
|
314
316
|
)
|
|
315
317
|
file_import.add_submodule_import(
|
|
316
|
-
|
|
318
|
+
"rest",
|
|
317
319
|
"HttpRequest",
|
|
318
320
|
ImportType.SDKCORE,
|
|
319
321
|
TypingSection.CONDITIONAL,
|
|
@@ -412,9 +414,11 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
|
|
|
412
414
|
return f"{super().name}Configuration"
|
|
413
415
|
|
|
414
416
|
def _imports_shared(self, async_mode: bool) -> FileImport:
|
|
415
|
-
file_import = self.
|
|
417
|
+
file_import = FileImport(self.code_model)
|
|
416
418
|
file_import.add_submodule_import(
|
|
417
|
-
|
|
419
|
+
"runtime" if self.code_model.options["unbranded"] else "pipeline",
|
|
420
|
+
"policies",
|
|
421
|
+
ImportType.SDKCORE,
|
|
418
422
|
)
|
|
419
423
|
file_import.add_submodule_import(
|
|
420
424
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
|
-
from typing import List, Dict, Any, Set, Union
|
|
6
|
+
from typing import List, Dict, Any, Set, Union, Literal
|
|
7
7
|
|
|
8
8
|
from .base import BaseType
|
|
9
9
|
from .enum_type import EnumType
|
|
@@ -202,6 +202,10 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
202
202
|
"""All of the enums"""
|
|
203
203
|
return [t for t in self.types_map.values() if isinstance(t, EnumType)]
|
|
204
204
|
|
|
205
|
+
@property
|
|
206
|
+
def core_library(self) -> Literal["azure.core", "corehttp"]:
|
|
207
|
+
return "azure.core" if not self.options["unbranded"] else "corehttp"
|
|
208
|
+
|
|
205
209
|
def _sort_model_types_helper(
|
|
206
210
|
self,
|
|
207
211
|
current: ModelType,
|
|
@@ -103,7 +103,7 @@ class CombinedType(BaseType):
|
|
|
103
103
|
raise ValueError("You shouldn't do instance checks on a multiple type")
|
|
104
104
|
|
|
105
105
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
106
|
-
file_import = self.
|
|
106
|
+
file_import = FileImport(self.code_model)
|
|
107
107
|
if self.name and not kwargs.get("is_types_file"):
|
|
108
108
|
file_import.add_submodule_import(
|
|
109
109
|
kwargs.pop("relative_path"),
|
|
@@ -124,7 +124,7 @@ class ConstantType(BaseType):
|
|
|
124
124
|
)
|
|
125
125
|
|
|
126
126
|
def _imports_shared(self, **kwargs: Any):
|
|
127
|
-
file_import =
|
|
127
|
+
file_import = super().imports(**kwargs)
|
|
128
128
|
file_import.merge(self.value_type.imports(**kwargs))
|
|
129
129
|
return file_import
|
|
130
130
|
|
|
@@ -86,9 +86,9 @@ class KeyCredentialPolicyType(_CredentialPolicyBaseType):
|
|
|
86
86
|
@property
|
|
87
87
|
def credential_name(self) -> str:
|
|
88
88
|
return (
|
|
89
|
-
"
|
|
90
|
-
if
|
|
91
|
-
else "
|
|
89
|
+
"ServiceKeyCredential"
|
|
90
|
+
if self.code_model.options["unbranded"]
|
|
91
|
+
else "AzureKeyCredential"
|
|
92
92
|
)
|
|
93
93
|
|
|
94
94
|
def call(self, async_mode: bool) -> str:
|
|
@@ -186,23 +186,31 @@ class TokenCredentialType(
|
|
|
186
186
|
def type_description(self) -> str:
|
|
187
187
|
return "TokenCredential"
|
|
188
188
|
|
|
189
|
+
@property
|
|
190
|
+
def credentials_subfolder(self) -> str:
|
|
191
|
+
return (
|
|
192
|
+
"credentials"
|
|
193
|
+
if self.code_model.options["unbranded"]
|
|
194
|
+
else "credentials_async"
|
|
195
|
+
)
|
|
196
|
+
|
|
189
197
|
def docstring_type(self, **kwargs: Any) -> str:
|
|
190
198
|
if kwargs.get("async_mode"):
|
|
191
|
-
return f"~{self.
|
|
192
|
-
return f"~{self.
|
|
199
|
+
return f"~{self.code_model.core_library}.{self.credentials_subfolder}.AsyncTokenCredential"
|
|
200
|
+
return f"~{self.code_model.core_library}.credentials.TokenCredential"
|
|
193
201
|
|
|
194
202
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
195
|
-
file_import =
|
|
203
|
+
file_import = super().imports(**kwargs)
|
|
196
204
|
if kwargs.get("async_mode"):
|
|
197
205
|
file_import.add_submodule_import(
|
|
198
|
-
|
|
206
|
+
self.credentials_subfolder,
|
|
199
207
|
"AsyncTokenCredential",
|
|
200
208
|
ImportType.SDKCORE,
|
|
201
209
|
typing_section=TypingSection.TYPING,
|
|
202
210
|
)
|
|
203
211
|
else:
|
|
204
212
|
file_import.add_submodule_import(
|
|
205
|
-
|
|
213
|
+
"credentials",
|
|
206
214
|
"TokenCredential",
|
|
207
215
|
ImportType.SDKCORE,
|
|
208
216
|
typing_section=TypingSection.TYPING,
|
|
@@ -221,7 +229,9 @@ class KeyCredentialType(
|
|
|
221
229
|
"""Type for an KeyCredential"""
|
|
222
230
|
|
|
223
231
|
def docstring_type(self, **kwargs: Any) -> str: # pylint: disable=unused-argument
|
|
224
|
-
return
|
|
232
|
+
return (
|
|
233
|
+
f"~{self.code_model.core_library}.credentials.{self.policy.credential_name}"
|
|
234
|
+
)
|
|
225
235
|
|
|
226
236
|
def type_annotation(self, **kwargs: Any) -> str: # pylint: disable=unused-argument
|
|
227
237
|
return self.policy.credential_name
|
|
@@ -231,9 +241,9 @@ class KeyCredentialType(
|
|
|
231
241
|
return "isinstance({}, " + f"{self.policy.credential_name})"
|
|
232
242
|
|
|
233
243
|
def imports(self, **kwargs: Any) -> FileImport: # pylint: disable=unused-argument
|
|
234
|
-
file_import =
|
|
244
|
+
file_import = super().imports(**kwargs)
|
|
235
245
|
file_import.add_submodule_import(
|
|
236
|
-
|
|
246
|
+
"credentials",
|
|
237
247
|
self.policy.credential_name,
|
|
238
248
|
ImportType.SDKCORE,
|
|
239
249
|
typing_section=TypingSection.CONDITIONAL,
|
|
@@ -123,7 +123,7 @@ class DictionaryType(BaseType):
|
|
|
123
123
|
)
|
|
124
124
|
|
|
125
125
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
126
|
-
file_import = self.
|
|
126
|
+
file_import = FileImport(self.code_model)
|
|
127
127
|
file_import.add_submodule_import(
|
|
128
128
|
"typing", "Dict", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
129
129
|
)
|
|
@@ -76,7 +76,7 @@ class EnumValue(BaseType):
|
|
|
76
76
|
return self.value_type.instance_check_template
|
|
77
77
|
|
|
78
78
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
79
|
-
file_import = self.
|
|
79
|
+
file_import = FileImport(self.code_model)
|
|
80
80
|
file_import.merge(self.value_type.imports(**kwargs))
|
|
81
81
|
file_import.add_literal_import()
|
|
82
82
|
file_import.add_submodule_import(
|
|
@@ -230,7 +230,7 @@ class EnumType(BaseType):
|
|
|
230
230
|
|
|
231
231
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
232
232
|
operation = kwargs.pop("operation", False)
|
|
233
|
-
file_import = self.
|
|
233
|
+
file_import = FileImport(self.code_model)
|
|
234
234
|
if self.code_model.options["models_mode"]:
|
|
235
235
|
file_import.add_submodule_import(
|
|
236
236
|
"typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
@@ -11,6 +11,10 @@ if TYPE_CHECKING:
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class ImportType(str, Enum):
|
|
14
|
+
"""
|
|
15
|
+
Ordering of these enum matters. We order import groupings in a file based off of this ordering.
|
|
16
|
+
"""
|
|
17
|
+
|
|
14
18
|
STDLIB = "stdlib"
|
|
15
19
|
THIRDPARTY = "thirdparty"
|
|
16
20
|
SDKCORE = "sdkcore"
|
|
@@ -87,14 +91,27 @@ class TypeDefinition:
|
|
|
87
91
|
self.async_definition = async_definition
|
|
88
92
|
|
|
89
93
|
|
|
90
|
-
class FileImport:
|
|
94
|
+
class FileImport:
|
|
91
95
|
def __init__(self, code_model: "CodeModel") -> None:
|
|
92
96
|
self.imports: List[ImportModel] = []
|
|
93
97
|
self.code_model = code_model
|
|
94
98
|
# has sync and async type definitions
|
|
95
99
|
self.type_definitions: Dict[str, TypeDefinition] = {}
|
|
100
|
+
self.core_library = self.code_model.core_library
|
|
96
101
|
|
|
97
102
|
def _append_import(self, import_model: ImportModel) -> None:
|
|
103
|
+
if import_model.import_type == ImportType.SDKCORE:
|
|
104
|
+
mod_name = import_model.module_name
|
|
105
|
+
core_libraries = [
|
|
106
|
+
self.code_model.core_library,
|
|
107
|
+
"azure",
|
|
108
|
+
"msrest",
|
|
109
|
+
]
|
|
110
|
+
if all(l not in mod_name for l in core_libraries):
|
|
111
|
+
# this is to make sure we don't tack on core libraries when we don't need to
|
|
112
|
+
import_model.module_name = (
|
|
113
|
+
f"{self.code_model.core_library}{'.' if mod_name else ''}{mod_name}"
|
|
114
|
+
)
|
|
98
115
|
if not any(
|
|
99
116
|
i
|
|
100
117
|
for i in self.imports
|
|
@@ -312,71 +329,3 @@ class FileImport: # pylint: disable=too-many-public-methods
|
|
|
312
329
|
ImportType.LOCAL,
|
|
313
330
|
typing_section,
|
|
314
331
|
)
|
|
315
|
-
|
|
316
|
-
@property
|
|
317
|
-
def import_core(self) -> str:
|
|
318
|
-
return "azure.core" if not self.code_model.options["unbranded"] else "corehttp"
|
|
319
|
-
|
|
320
|
-
@property
|
|
321
|
-
def import_core_exceptions(self) -> str:
|
|
322
|
-
return f"{self.import_core}.exceptions"
|
|
323
|
-
|
|
324
|
-
@property
|
|
325
|
-
def import_core_rest(self) -> str:
|
|
326
|
-
return f"{self.import_core}.rest"
|
|
327
|
-
|
|
328
|
-
@property
|
|
329
|
-
def import_core_credentials(self) -> str:
|
|
330
|
-
return f"{self.import_core}.credentials"
|
|
331
|
-
|
|
332
|
-
@property
|
|
333
|
-
def import_core_credentials_async(self) -> str:
|
|
334
|
-
return self.import_core + (
|
|
335
|
-
".credentials_async"
|
|
336
|
-
if not self.code_model.options["unbranded"]
|
|
337
|
-
else ".credentials"
|
|
338
|
-
)
|
|
339
|
-
|
|
340
|
-
@property
|
|
341
|
-
def import_core_paging(self) -> str:
|
|
342
|
-
return f"{self.import_core}.paging"
|
|
343
|
-
|
|
344
|
-
@property
|
|
345
|
-
def import_core_paging_async(self) -> str:
|
|
346
|
-
return self.import_core + (
|
|
347
|
-
".async_paging" if not self.code_model.options["unbranded"] else ".paging"
|
|
348
|
-
)
|
|
349
|
-
|
|
350
|
-
@property
|
|
351
|
-
def import_core_utils(self) -> str:
|
|
352
|
-
return f"{self.import_core}.utils"
|
|
353
|
-
|
|
354
|
-
@property
|
|
355
|
-
def import_core_case_insensitive_enum(self) -> str:
|
|
356
|
-
return self.import_core + (
|
|
357
|
-
"" if not self.code_model.options["unbranded"] else ".utils"
|
|
358
|
-
)
|
|
359
|
-
|
|
360
|
-
@property
|
|
361
|
-
def import_core_pipeline(self) -> str:
|
|
362
|
-
return self.import_core + (
|
|
363
|
-
".pipeline"
|
|
364
|
-
if not self.code_model.options["unbranded"]
|
|
365
|
-
else ".runtime.pipeline"
|
|
366
|
-
)
|
|
367
|
-
|
|
368
|
-
@property
|
|
369
|
-
def import_core_policies(self) -> str:
|
|
370
|
-
return self.import_core + (
|
|
371
|
-
".pipeline" if not self.code_model.options["unbranded"] else ".runtime"
|
|
372
|
-
)
|
|
373
|
-
|
|
374
|
-
@property
|
|
375
|
-
def import_core_serialization(self) -> str:
|
|
376
|
-
return f"{self.import_core}.serialization"
|
|
377
|
-
|
|
378
|
-
@property
|
|
379
|
-
def import_core_pipeline_client(self) -> str:
|
|
380
|
-
return self.import_core + (
|
|
381
|
-
"" if not self.code_model.options["unbranded"] else ".runtime"
|
|
382
|
-
)
|
|
@@ -146,7 +146,7 @@ class ListType(BaseType):
|
|
|
146
146
|
)
|
|
147
147
|
|
|
148
148
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
149
|
-
file_import = self.
|
|
149
|
+
file_import = FileImport(self.code_model)
|
|
150
150
|
if not (
|
|
151
151
|
self.code_model.options["version_tolerant"]
|
|
152
152
|
and self.element_type.is_xml
|
|
@@ -268,7 +268,7 @@ class JSONModelType(ModelType):
|
|
|
268
268
|
return "isinstance({}, MutableMapping)"
|
|
269
269
|
|
|
270
270
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
271
|
-
file_import = self.
|
|
271
|
+
file_import = FileImport(self.code_model)
|
|
272
272
|
file_import.add_submodule_import(
|
|
273
273
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
274
274
|
)
|
|
@@ -230,7 +230,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
230
230
|
def _imports_shared(
|
|
231
231
|
self, async_mode: bool, **kwargs: Any # pylint: disable=unused-argument
|
|
232
232
|
) -> FileImport:
|
|
233
|
-
file_import = self.
|
|
233
|
+
file_import = FileImport(self.code_model)
|
|
234
234
|
file_import.add_submodule_import(
|
|
235
235
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
236
236
|
)
|
|
@@ -308,7 +308,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
308
308
|
async_mode: bool,
|
|
309
309
|
) -> FileImport:
|
|
310
310
|
"""Helper method to get a request builder import."""
|
|
311
|
-
file_import = self.
|
|
311
|
+
file_import = FileImport(self.code_model)
|
|
312
312
|
if self.code_model.options["builders_visibility"] != "embedded":
|
|
313
313
|
group_name = request_builder.group_name
|
|
314
314
|
rest_import_path = "..." if async_mode else ".."
|
|
@@ -338,7 +338,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
338
338
|
self, async_mode: bool, **kwargs: Any
|
|
339
339
|
) -> FileImport:
|
|
340
340
|
if self.abstract:
|
|
341
|
-
return self.
|
|
341
|
+
return FileImport(self.code_model)
|
|
342
342
|
file_import = self._imports_shared(async_mode, **kwargs)
|
|
343
343
|
|
|
344
344
|
for param in self.parameters.method:
|
|
@@ -378,9 +378,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
378
378
|
"ResourceNotModifiedError",
|
|
379
379
|
]
|
|
380
380
|
for error in errors:
|
|
381
|
-
file_import.add_submodule_import(
|
|
382
|
-
file_import.import_core_exceptions, error, ImportType.SDKCORE
|
|
383
|
-
)
|
|
381
|
+
file_import.add_submodule_import("exceptions", error, ImportType.SDKCORE)
|
|
384
382
|
if self.code_model.options["azure_arm"]:
|
|
385
383
|
file_import.add_submodule_import(
|
|
386
384
|
"azure.mgmt.core.exceptions", "ARMErrorFormat", ImportType.SDKCORE
|
|
@@ -392,7 +390,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
392
390
|
self.parameters.kwargs_to_pop, ParameterLocation.QUERY # type: ignore
|
|
393
391
|
):
|
|
394
392
|
file_import.add_submodule_import(
|
|
395
|
-
|
|
393
|
+
"utils",
|
|
396
394
|
"case_insensitive_dict",
|
|
397
395
|
ImportType.SDKCORE,
|
|
398
396
|
)
|
|
@@ -406,7 +404,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
406
404
|
)
|
|
407
405
|
if self.has_etag:
|
|
408
406
|
file_import.add_submodule_import(
|
|
409
|
-
|
|
407
|
+
"exceptions",
|
|
410
408
|
"ResourceModifiedError",
|
|
411
409
|
ImportType.SDKCORE,
|
|
412
410
|
)
|
|
@@ -433,13 +431,13 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
433
431
|
else:
|
|
434
432
|
if async_mode:
|
|
435
433
|
file_import.add_submodule_import(
|
|
436
|
-
|
|
434
|
+
"rest",
|
|
437
435
|
"AsyncHttpResponse",
|
|
438
436
|
ImportType.SDKCORE,
|
|
439
437
|
)
|
|
440
438
|
else:
|
|
441
439
|
file_import.add_submodule_import(
|
|
442
|
-
|
|
440
|
+
"rest",
|
|
443
441
|
"HttpResponse",
|
|
444
442
|
ImportType.SDKCORE,
|
|
445
443
|
)
|
|
@@ -449,13 +447,11 @@ class OperationBase( # pylint: disable=too-many-public-methods
|
|
|
449
447
|
):
|
|
450
448
|
file_import.merge(self.request_builder.imports())
|
|
451
449
|
file_import.add_submodule_import(
|
|
452
|
-
|
|
450
|
+
f"{'runtime.' if self.code_model.options['unbranded'] else ''}pipeline",
|
|
453
451
|
"PipelineResponse",
|
|
454
452
|
ImportType.SDKCORE,
|
|
455
453
|
)
|
|
456
|
-
file_import.add_submodule_import(
|
|
457
|
-
file_import.import_core_rest, "HttpRequest", ImportType.SDKCORE
|
|
458
|
-
)
|
|
454
|
+
file_import.add_submodule_import("rest", "HttpRequest", ImportType.SDKCORE)
|
|
459
455
|
file_import.add_submodule_import(
|
|
460
456
|
"typing", "Callable", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
461
457
|
)
|
|
@@ -576,7 +572,7 @@ class Operation(OperationBase[Response]):
|
|
|
576
572
|
relative_path = "..." if async_mode else ".."
|
|
577
573
|
if self.parameters.has_body:
|
|
578
574
|
file_import.add_submodule_import(
|
|
579
|
-
f"{relative_path}_model_base", "
|
|
575
|
+
f"{relative_path}_model_base", "SdkJSONEncoder", ImportType.LOCAL
|
|
580
576
|
)
|
|
581
577
|
file_import.add_import("json", ImportType.STDLIB)
|
|
582
578
|
if self.default_error_deserialization or any(
|
|
@@ -48,7 +48,7 @@ class OperationGroup(BaseModel):
|
|
|
48
48
|
return ", ".join(base_classes)
|
|
49
49
|
|
|
50
50
|
def imports_for_multiapi(self, async_mode: bool) -> FileImport:
|
|
51
|
-
file_import = self.
|
|
51
|
+
file_import = FileImport(self.code_model)
|
|
52
52
|
relative_path = ".." if async_mode else "."
|
|
53
53
|
for operation in self.operations:
|
|
54
54
|
file_import.merge(
|
|
@@ -79,7 +79,7 @@ class OperationGroup(BaseModel):
|
|
|
79
79
|
return any(o for o in self.operations if o.need_validation)
|
|
80
80
|
|
|
81
81
|
def imports(self, async_mode: bool) -> FileImport:
|
|
82
|
-
file_import = self.
|
|
82
|
+
file_import = FileImport(self.code_model)
|
|
83
83
|
|
|
84
84
|
relative_path = ("..." if async_mode else "..") + (
|
|
85
85
|
"." if self.client.is_subclient else ""
|
|
@@ -62,11 +62,11 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
62
62
|
self.override_success_response_to_200 = override_success_response_to_200
|
|
63
63
|
self.pager_sync: str = (
|
|
64
64
|
yaml_data.get("pagerSync")
|
|
65
|
-
or f"{self.
|
|
65
|
+
or f"{self.code_model.core_library}.paging.ItemPaged"
|
|
66
66
|
)
|
|
67
67
|
self.pager_async: str = (
|
|
68
68
|
yaml_data.get("pagerAsync")
|
|
69
|
-
or f"{self.
|
|
69
|
+
or f"{self.code_model.core_library}.paging.AsyncItemPaged"
|
|
70
70
|
)
|
|
71
71
|
|
|
72
72
|
def _get_attr_name(self, wire_name: str) -> str:
|
|
@@ -150,7 +150,7 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
150
150
|
|
|
151
151
|
def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
|
|
152
152
|
if self.abstract:
|
|
153
|
-
return self.
|
|
153
|
+
return FileImport(self.code_model)
|
|
154
154
|
file_import = self._imports_shared(async_mode, **kwargs)
|
|
155
155
|
file_import.merge(super().imports(async_mode, **kwargs))
|
|
156
156
|
if self.code_model.options["tracing"] and self.want_tracing:
|
|
@@ -166,7 +166,7 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
|
|
|
166
166
|
elif any(p.is_api_version for p in self.client.parameters):
|
|
167
167
|
file_import.add_import("urllib.parse", ImportType.STDLIB)
|
|
168
168
|
file_import.add_submodule_import(
|
|
169
|
-
|
|
169
|
+
"utils",
|
|
170
170
|
"case_insensitive_dict",
|
|
171
171
|
ImportType.SDKCORE,
|
|
172
172
|
)
|
|
@@ -168,7 +168,7 @@ class _ParameterBase(
|
|
|
168
168
|
return self.type.serialization_type
|
|
169
169
|
|
|
170
170
|
def _imports_shared(self, async_mode: bool, **_: Any) -> FileImport:
|
|
171
|
-
file_import = self.
|
|
171
|
+
file_import = FileImport(self.code_model)
|
|
172
172
|
if self.optional and self.client_default_value is None:
|
|
173
173
|
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
|
|
174
174
|
if self.added_on:
|
|
@@ -107,7 +107,7 @@ class BinaryType(PrimitiveType):
|
|
|
107
107
|
from .combined_type import CombinedType
|
|
108
108
|
from .operation import OperationBase
|
|
109
109
|
|
|
110
|
-
file_import = self.
|
|
110
|
+
file_import = FileImport(self.code_model)
|
|
111
111
|
file_import.add_submodule_import("typing", "IO", ImportType.STDLIB)
|
|
112
112
|
operation = kwargs.get("operation")
|
|
113
113
|
if (
|
|
@@ -145,7 +145,7 @@ class BinaryIteratorType(PrimitiveType):
|
|
|
145
145
|
return self.get_declaration("Iterator[bytes]")
|
|
146
146
|
|
|
147
147
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
148
|
-
file_import = self.
|
|
148
|
+
file_import = FileImport(self.code_model)
|
|
149
149
|
iterator = "AsyncIterator" if kwargs.get("async_mode") else "Iterator"
|
|
150
150
|
file_import.add_submodule_import("typing", iterator, ImportType.STDLIB)
|
|
151
151
|
return file_import
|
|
@@ -171,7 +171,7 @@ class AnyType(PrimitiveType):
|
|
|
171
171
|
return self.get_declaration({})
|
|
172
172
|
|
|
173
173
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
174
|
-
file_import = self.
|
|
174
|
+
file_import = FileImport(self.code_model)
|
|
175
175
|
file_import.add_submodule_import(
|
|
176
176
|
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
|
|
177
177
|
)
|
|
@@ -204,7 +204,7 @@ class AnyObjectType(PrimitiveType):
|
|
|
204
204
|
return "isinstance({}, MutableMapping)"
|
|
205
205
|
|
|
206
206
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
207
|
-
file_import = self.
|
|
207
|
+
file_import = FileImport(self.code_model)
|
|
208
208
|
file_import.define_mutable_mapping_type()
|
|
209
209
|
return file_import
|
|
210
210
|
|
|
@@ -386,7 +386,7 @@ class DatetimeType(PrimitiveType):
|
|
|
386
386
|
return f'"{value}"'
|
|
387
387
|
|
|
388
388
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
389
|
-
file_import = self.
|
|
389
|
+
file_import = FileImport(self.code_model)
|
|
390
390
|
file_import.add_import("datetime", ImportType.STDLIB)
|
|
391
391
|
return file_import
|
|
392
392
|
|
|
@@ -429,7 +429,7 @@ class TimeType(PrimitiveType):
|
|
|
429
429
|
return f'"{value}"'
|
|
430
430
|
|
|
431
431
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
432
|
-
file_import = self.
|
|
432
|
+
file_import = FileImport(self.code_model)
|
|
433
433
|
file_import.add_import("datetime", ImportType.STDLIB)
|
|
434
434
|
return file_import
|
|
435
435
|
|
|
@@ -476,7 +476,7 @@ class UnixTimeType(PrimitiveType):
|
|
|
476
476
|
return f'"{value}"'
|
|
477
477
|
|
|
478
478
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
479
|
-
file_import = self.
|
|
479
|
+
file_import = FileImport(self.code_model)
|
|
480
480
|
file_import.add_import("datetime", ImportType.STDLIB)
|
|
481
481
|
return file_import
|
|
482
482
|
|
|
@@ -519,7 +519,7 @@ class DateType(PrimitiveType):
|
|
|
519
519
|
return f'"{value}"'
|
|
520
520
|
|
|
521
521
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
522
|
-
file_import = self.
|
|
522
|
+
file_import = FileImport(self.code_model)
|
|
523
523
|
file_import.add_import("datetime", ImportType.STDLIB)
|
|
524
524
|
return file_import
|
|
525
525
|
|
|
@@ -562,7 +562,7 @@ class DurationType(PrimitiveType):
|
|
|
562
562
|
return f'"{value}"'
|
|
563
563
|
|
|
564
564
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
565
|
-
file_import = self.
|
|
565
|
+
file_import = FileImport(self.code_model)
|
|
566
566
|
file_import.add_import("datetime", ImportType.STDLIB)
|
|
567
567
|
return file_import
|
|
568
568
|
|
|
@@ -612,18 +612,14 @@ class SdkCoreType(PrimitiveType):
|
|
|
612
612
|
self.name = yaml_data.get("name", "")
|
|
613
613
|
|
|
614
614
|
def docstring_type(self, **kwargs: Any) -> str:
|
|
615
|
-
return f"~{self.
|
|
616
|
-
**kwargs
|
|
617
|
-
)
|
|
615
|
+
return f"~{self.code_model.core_library}.{self.type_annotation(**kwargs)}"
|
|
618
616
|
|
|
619
617
|
def type_annotation(self, **kwargs: Any) -> str:
|
|
620
618
|
return self.name
|
|
621
619
|
|
|
622
620
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
623
|
-
file_import =
|
|
624
|
-
file_import.add_submodule_import(
|
|
625
|
-
file_import.import_core, self.name, ImportType.SDKCORE
|
|
626
|
-
)
|
|
621
|
+
file_import = super().imports(**kwargs)
|
|
622
|
+
file_import.add_submodule_import("", self.name, ImportType.SDKCORE)
|
|
627
623
|
return file_import
|
|
628
624
|
|
|
629
625
|
@property
|
|
@@ -147,7 +147,7 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
|
|
|
147
147
|
return retval or None
|
|
148
148
|
|
|
149
149
|
def imports(self, **kwargs) -> FileImport:
|
|
150
|
-
file_import = self.
|
|
150
|
+
file_import = FileImport(self.code_model)
|
|
151
151
|
if self.is_discriminator and isinstance(self.type, EnumType):
|
|
152
152
|
return file_import
|
|
153
153
|
file_import.merge(
|