@autorest/python 6.9.3 → 6.9.5

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.
Files changed (48) hide show
  1. package/autorest/_utils.py +35 -20
  2. package/autorest/codegen/__init__.py +252 -133
  3. package/autorest/codegen/_utils.py +2 -2
  4. package/autorest/codegen/models/__init__.py +7 -7
  5. package/autorest/codegen/models/base.py +6 -4
  6. package/autorest/codegen/models/client.py +34 -28
  7. package/autorest/codegen/models/combined_type.py +1 -1
  8. package/autorest/codegen/models/constant_type.py +1 -1
  9. package/autorest/codegen/models/credential_types.py +33 -23
  10. package/autorest/codegen/models/dictionary_type.py +1 -1
  11. package/autorest/codegen/models/enum_type.py +2 -2
  12. package/autorest/codegen/models/imports.py +77 -8
  13. package/autorest/codegen/models/list_type.py +1 -1
  14. package/autorest/codegen/models/lro_operation.py +5 -2
  15. package/autorest/codegen/models/model_type.py +1 -1
  16. package/autorest/codegen/models/operation.py +26 -18
  17. package/autorest/codegen/models/operation_group.py +2 -2
  18. package/autorest/codegen/models/paging_operation.py +13 -5
  19. package/autorest/codegen/models/parameter.py +1 -1
  20. package/autorest/codegen/models/primitive_types.py +27 -28
  21. package/autorest/codegen/models/property.py +3 -1
  22. package/autorest/codegen/models/request_builder.py +11 -10
  23. package/autorest/codegen/models/response.py +26 -14
  24. package/autorest/codegen/serializers/__init__.py +5 -0
  25. package/autorest/codegen/serializers/base_serializer.py +21 -0
  26. package/autorest/codegen/serializers/builder_serializer.py +39 -22
  27. package/autorest/codegen/serializers/client_serializer.py +20 -5
  28. package/autorest/codegen/serializers/enum_serializer.py +5 -8
  29. package/autorest/codegen/serializers/general_serializer.py +22 -27
  30. package/autorest/codegen/serializers/model_serializer.py +8 -10
  31. package/autorest/codegen/serializers/operation_groups_serializer.py +4 -5
  32. package/autorest/codegen/serializers/patch_serializer.py +4 -8
  33. package/autorest/codegen/serializers/request_builders_serializer.py +4 -4
  34. package/autorest/codegen/serializers/sample_serializer.py +11 -9
  35. package/autorest/codegen/serializers/types_serializer.py +3 -8
  36. package/autorest/codegen/templates/config.py.jinja2 +3 -1
  37. package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
  38. package/autorest/codegen/templates/model_base.py.jinja2 +5 -5
  39. package/autorest/codegen/templates/packaging_templates/LICENSE.jinja2 +1 -1
  40. package/autorest/codegen/templates/packaging_templates/README.md.jinja2 +3 -1
  41. package/autorest/codegen/templates/packaging_templates/setup.py.jinja2 +7 -3
  42. package/autorest/codegen/templates/serialization.py.jinja2 +17 -18
  43. package/autorest/jsonrpc/server.py +5 -1
  44. package/autorest/m4reformatter/__init__.py +1 -1
  45. package/autorest/multiapi/models/imports.py +18 -16
  46. package/autorest/multiapi/serializers/__init__.py +4 -1
  47. package/autorest/preprocess/__init__.py +1 -9
  48. package/package.json +1 -1
@@ -195,18 +195,19 @@ 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 = FileImport()
199
-
198
+ file_import = self.init_file_import()
200
199
  file_import.add_submodule_import(
201
200
  "typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
202
201
  )
203
202
  if self.code_model.options["azure_arm"]:
204
203
  file_import.add_submodule_import(
205
- "azure.mgmt.core", self.pipeline_class(async_mode), ImportType.AZURECORE
204
+ "azure.mgmt.core", self.pipeline_class(async_mode), ImportType.SDKCORE
206
205
  )
207
206
  else:
208
207
  file_import.add_submodule_import(
209
- "azure.core", self.pipeline_class(async_mode), ImportType.AZURECORE
208
+ file_import.import_core_pipeline_client,
209
+ self.pipeline_class(async_mode),
210
+ ImportType.SDKCORE,
210
211
  )
211
212
 
212
213
  for gp in self.parameters:
@@ -225,20 +226,19 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
225
226
  ImportType.LOCAL,
226
227
  )
227
228
  file_import.add_msrest_import(
228
- self.code_model,
229
- ".." if async_mode else ".",
230
- MsrestImportType.SerializerDeserializer,
231
- TypingSection.REGULAR,
229
+ relative_path=".." if async_mode else ".",
230
+ msrest_import_type=MsrestImportType.SerializerDeserializer,
231
+ typing_section=TypingSection.REGULAR,
232
232
  )
233
233
  file_import.add_submodule_import(
234
- "azure.core.pipeline", "policies", ImportType.AZURECORE
234
+ file_import.import_core_policies, "policies", ImportType.SDKCORE
235
235
  )
236
236
  if self.code_model.options["azure_arm"]:
237
237
  async_prefix = "Async" if async_mode else ""
238
238
  file_import.add_submodule_import(
239
239
  "azure.mgmt.core.policies",
240
240
  f"{async_prefix}ARMAutoResourceProviderRegistrationPolicy",
241
- ImportType.AZURECORE,
241
+ ImportType.SDKCORE,
242
242
  )
243
243
  return file_import
244
244
 
@@ -248,13 +248,19 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
248
248
  return any(o for o in self.operation_groups if o.is_mixin)
249
249
 
250
250
  @property
251
- def has_public_lro_operations(self) -> bool:
252
- """Are there any LRO operations in this SDK?"""
253
- return any(
254
- operation.operation_type in ("lro", "lropaging") and not operation.internal
251
+ def lro_operations(self) -> List["OperationType"]:
252
+ """all LRO operations in this SDK?"""
253
+ return [
254
+ operation
255
255
  for operation_group in self.operation_groups
256
256
  for operation in operation_group.operations
257
- )
257
+ if operation.operation_type in ("lro", "lropaging")
258
+ ]
259
+
260
+ @property
261
+ def has_public_lro_operations(self) -> bool:
262
+ """Are there any public LRO operations in this SDK?"""
263
+ return any(not operation.internal for operation in self.lro_operations)
258
264
 
259
265
  @property
260
266
  def has_operations(self) -> bool:
@@ -294,22 +300,22 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
294
300
  if async_mode:
295
301
  file_import.add_submodule_import("typing", "Awaitable", ImportType.STDLIB)
296
302
  file_import.add_submodule_import(
297
- "azure.core.rest",
303
+ file_import.import_core_rest,
298
304
  "AsyncHttpResponse",
299
- ImportType.AZURECORE,
305
+ ImportType.SDKCORE,
300
306
  TypingSection.CONDITIONAL,
301
307
  )
302
308
  else:
303
309
  file_import.add_submodule_import(
304
- "azure.core.rest",
310
+ file_import.import_core_rest,
305
311
  "HttpResponse",
306
- ImportType.AZURECORE,
312
+ ImportType.SDKCORE,
307
313
  TypingSection.CONDITIONAL,
308
314
  )
309
315
  file_import.add_submodule_import(
310
- "azure.core.rest",
316
+ file_import.import_core_rest,
311
317
  "HttpRequest",
312
- ImportType.AZURECORE,
318
+ ImportType.SDKCORE,
313
319
  TypingSection.CONDITIONAL,
314
320
  )
315
321
  for og in self.operation_groups:
@@ -349,15 +355,15 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
349
355
  except StopIteration:
350
356
  pass
351
357
  file_import.add_submodule_import(
352
- "azure.profiles", "KnownProfiles", import_type=ImportType.AZURECORE
358
+ "azure.profiles", "KnownProfiles", import_type=ImportType.SDKCORE
353
359
  )
354
360
  file_import.add_submodule_import(
355
- "azure.profiles", "ProfileDefinition", import_type=ImportType.AZURECORE
361
+ "azure.profiles", "ProfileDefinition", import_type=ImportType.SDKCORE
356
362
  )
357
363
  file_import.add_submodule_import(
358
364
  "azure.profiles.multiapiclient",
359
365
  "MultiApiClientMixin",
360
- import_type=ImportType.AZURECORE,
366
+ import_type=ImportType.SDKCORE,
361
367
  )
362
368
  return file_import
363
369
 
@@ -406,9 +412,9 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
406
412
  return f"{super().name}Configuration"
407
413
 
408
414
  def _imports_shared(self, async_mode: bool) -> FileImport:
409
- file_import = FileImport()
415
+ file_import = self.init_file_import()
410
416
  file_import.add_submodule_import(
411
- "azure.core.pipeline", "policies", ImportType.AZURECORE
417
+ file_import.import_core_policies, "policies", ImportType.SDKCORE
412
418
  )
413
419
  file_import.add_submodule_import(
414
420
  "typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
@@ -424,10 +430,10 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
424
430
  else "ARMChallengeAuthenticationPolicy"
425
431
  )
426
432
  file_import.add_submodule_import(
427
- "azure.mgmt.core.policies", "ARMHttpLoggingPolicy", ImportType.AZURECORE
433
+ "azure.mgmt.core.policies", "ARMHttpLoggingPolicy", ImportType.SDKCORE
428
434
  )
429
435
  file_import.add_submodule_import(
430
- "azure.mgmt.core.policies", policy, ImportType.AZURECORE
436
+ "azure.mgmt.core.policies", policy, ImportType.SDKCORE
431
437
  )
432
438
 
433
439
  return file_import
@@ -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 = FileImport()
106
+ file_import = self.init_file_import()
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 = FileImport()
127
+ file_import = self.init_file_import()
128
128
  file_import.merge(self.value_type.imports(**kwargs))
129
129
  return file_import
130
130
 
@@ -26,7 +26,7 @@ if TYPE_CHECKING:
26
26
  class _CredentialPolicyBaseType:
27
27
  """Base class for our different credential policy types.
28
28
 
29
- Inherited by our BearerTokenCredentialPolicy and AzureKeyCredentialPolicy types.
29
+ Inherited by our BearerTokenCredentialPolicy and KeyCredentialPolicy types.
30
30
  """
31
31
 
32
32
  def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
@@ -71,7 +71,7 @@ class ARMChallengeAuthenticationPolicyType(BearerTokenCredentialPolicyType):
71
71
  return f"{policy_name}(self.credential, *self.credential_scopes, **kwargs)"
72
72
 
73
73
 
74
- class AzureKeyCredentialPolicyType(_CredentialPolicyBaseType):
74
+ class KeyCredentialPolicyType(_CredentialPolicyBaseType):
75
75
  def __init__(
76
76
  self,
77
77
  yaml_data: Dict[str, Any],
@@ -83,16 +83,26 @@ class AzureKeyCredentialPolicyType(_CredentialPolicyBaseType):
83
83
  self.key = key
84
84
  self.scheme = scheme
85
85
 
86
+ @property
87
+ def credential_name(self) -> str:
88
+ return (
89
+ "AzureKeyCredential"
90
+ if not self.code_model.options["unbranded"]
91
+ else "ServiceKeyCredential"
92
+ )
93
+
86
94
  def call(self, async_mode: bool) -> str:
87
95
  params = f'"{self.key}", '
88
96
  if self.scheme:
89
97
  params += f'prefix="{self.scheme}", '
90
- return f"policies.AzureKeyCredentialPolicy(self.credential, {params}**kwargs)"
98
+ return (
99
+ f"policies.{self.credential_name}Policy(self.credential, {params}**kwargs)"
100
+ )
91
101
 
92
102
  @classmethod
93
103
  def from_yaml(
94
104
  cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
95
- ) -> "AzureKeyCredentialPolicyType":
105
+ ) -> "KeyCredentialPolicyType":
96
106
  return cls(
97
107
  yaml_data, code_model, yaml_data["key"], yaml_data.get("scheme", None)
98
108
  )
@@ -103,7 +113,7 @@ CredentialPolicyType = TypeVar(
103
113
  bound=Union[
104
114
  BearerTokenCredentialPolicyType,
105
115
  ARMChallengeAuthenticationPolicyType,
106
- AzureKeyCredentialPolicyType,
116
+ KeyCredentialPolicyType,
107
117
  ],
108
118
  )
109
119
 
@@ -111,7 +121,7 @@ CredentialPolicyType = TypeVar(
111
121
  class CredentialType(
112
122
  Generic[CredentialPolicyType], BaseType
113
123
  ): # pylint:disable=abstract-method
114
- """Store info about the type of the credential. Can be either an AzureKeyCredential or a TokenCredential"""
124
+ """Store info about the type of the credential. Can be either an KeyCredential or a TokenCredential"""
115
125
 
116
126
  def __init__(
117
127
  self,
@@ -178,23 +188,23 @@ class TokenCredentialType(
178
188
 
179
189
  def docstring_type(self, **kwargs: Any) -> str:
180
190
  if kwargs.get("async_mode"):
181
- return "~azure.core.credentials_async.AsyncTokenCredential"
182
- return "~azure.core.credentials.TokenCredential"
191
+ return f"~{self.init_file_import().import_core_credentials_async}.AsyncTokenCredential"
192
+ return f"~{self.init_file_import().import_core_credentials}.TokenCredential"
183
193
 
184
194
  def imports(self, **kwargs: Any) -> FileImport:
185
- file_import = FileImport()
195
+ file_import = self.init_file_import()
186
196
  if kwargs.get("async_mode"):
187
197
  file_import.add_submodule_import(
188
- "azure.core.credentials_async",
198
+ file_import.import_core_credentials_async,
189
199
  "AsyncTokenCredential",
190
- ImportType.AZURECORE,
200
+ ImportType.SDKCORE,
191
201
  typing_section=TypingSection.TYPING,
192
202
  )
193
203
  else:
194
204
  file_import.add_submodule_import(
195
- "azure.core.credentials",
205
+ file_import.import_core_credentials,
196
206
  "TokenCredential",
197
- ImportType.AZURECORE,
207
+ ImportType.SDKCORE,
198
208
  typing_section=TypingSection.TYPING,
199
209
  )
200
210
  return file_import
@@ -204,28 +214,28 @@ class TokenCredentialType(
204
214
  return "hasattr({}, 'get_token')"
205
215
 
206
216
 
207
- class AzureKeyCredentialType(
217
+ class KeyCredentialType(
208
218
  # pylint: disable=unsubscriptable-object
209
- CredentialType[AzureKeyCredentialPolicyType]
219
+ CredentialType[KeyCredentialPolicyType]
210
220
  ):
211
- """Type for an AzureKeyCredential"""
221
+ """Type for an KeyCredential"""
212
222
 
213
223
  def docstring_type(self, **kwargs: Any) -> str: # pylint: disable=unused-argument
214
- return "~azure.core.credentials.AzureKeyCredential"
224
+ return f"~{self.init_file_import().import_core}.credentials.{self.policy.credential_name}"
215
225
 
216
226
  def type_annotation(self, **kwargs: Any) -> str: # pylint: disable=unused-argument
217
- return "AzureKeyCredential"
227
+ return self.policy.credential_name
218
228
 
219
229
  @property
220
230
  def instance_check_template(self) -> str:
221
- return "isinstance({}, AzureKeyCredential)"
231
+ return "isinstance({}, " + f"{self.policy.credential_name})"
222
232
 
223
233
  def imports(self, **kwargs: Any) -> FileImport: # pylint: disable=unused-argument
224
- file_import = FileImport()
234
+ file_import = self.init_file_import()
225
235
  file_import.add_submodule_import(
226
- "azure.core.credentials",
227
- "AzureKeyCredential",
228
- ImportType.AZURECORE,
236
+ f"{file_import.import_core}.credentials",
237
+ self.policy.credential_name,
238
+ ImportType.SDKCORE,
229
239
  typing_section=TypingSection.CONDITIONAL,
230
240
  )
231
241
  return file_import
@@ -123,7 +123,7 @@ class DictionaryType(BaseType):
123
123
  )
124
124
 
125
125
  def imports(self, **kwargs: Any) -> FileImport:
126
- file_import = FileImport()
126
+ file_import = self.init_file_import()
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 = FileImport()
79
+ file_import = self.init_file_import()
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 = FileImport()
233
+ file_import = self.init_file_import()
234
234
  if self.code_model.options["models_mode"]:
235
235
  file_import.add_submodule_import(
236
236
  "typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL
@@ -13,7 +13,7 @@ if TYPE_CHECKING:
13
13
  class ImportType(str, Enum):
14
14
  STDLIB = "stdlib"
15
15
  THIRDPARTY = "thirdparty"
16
- AZURECORE = "azurecore"
16
+ SDKCORE = "sdkcore"
17
17
  LOCAL = "local"
18
18
  BYVERSION = "by_version"
19
19
 
@@ -87,9 +87,10 @@ class TypeDefinition:
87
87
  self.async_definition = async_definition
88
88
 
89
89
 
90
- class FileImport:
91
- def __init__(self, imports: Optional[List[ImportModel]] = None) -> None:
92
- self.imports = imports or []
90
+ class FileImport: # pylint: disable=too-many-public-methods
91
+ def __init__(self, code_model: "CodeModel") -> None:
92
+ self.imports: List[ImportModel] = []
93
+ self.code_model = code_model
93
94
  # has sync and async type definitions
94
95
  self.type_definitions: Dict[str, TypeDefinition] = {}
95
96
 
@@ -272,15 +273,15 @@ class FileImport:
272
273
 
273
274
  def add_msrest_import(
274
275
  self,
275
- code_model: "CodeModel",
276
+ *,
276
277
  relative_path: str,
277
278
  msrest_import_type: MsrestImportType,
278
279
  typing_section: TypingSection,
279
280
  ):
280
- if code_model.options["client_side_validation"]:
281
+ if self.code_model.options["client_side_validation"]:
281
282
  if msrest_import_type == MsrestImportType.Module:
282
283
  self.add_import(
283
- "msrest.serialization", ImportType.AZURECORE, typing_section
284
+ "msrest.serialization", ImportType.SDKCORE, typing_section
284
285
  )
285
286
  else:
286
287
  self.add_submodule_import(
@@ -291,7 +292,7 @@ class FileImport:
291
292
  "msrest", "Deserializer", ImportType.THIRDPARTY, typing_section
292
293
  )
293
294
  else:
294
- if code_model.options["multiapi"]:
295
+ if self.code_model.options["multiapi"]:
295
296
  relative_path += "."
296
297
  if msrest_import_type == MsrestImportType.Module:
297
298
  self.add_submodule_import(
@@ -311,3 +312,71 @@ class FileImport:
311
312
  ImportType.LOCAL,
312
313
  typing_section,
313
314
  )
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 = FileImport()
149
+ file_import = self.init_file_import()
150
150
  if not (
151
151
  self.code_model.options["version_tolerant"]
152
152
  and self.element_type.is_xml
@@ -104,6 +104,9 @@ class LROOperationBase(OperationBase[LROResponseType]):
104
104
  """We don't want the poller to show up in ClsType, so we call super() on resposne type annotation"""
105
105
  return f"ClsType[{Response.type_annotation(self.responses[0], async_mode=async_mode)}]"
106
106
 
107
+ def get_poller_with_response_type(self, async_mode: bool) -> str:
108
+ return self.response_type_annotation(async_mode=async_mode)
109
+
107
110
  def get_poller(self, async_mode: bool) -> str:
108
111
  return self.responses[0].get_poller(async_mode)
109
112
 
@@ -123,11 +126,11 @@ class LROOperationBase(OperationBase[LROResponseType]):
123
126
  file_import = super().imports(async_mode, **kwargs)
124
127
  if self.abstract:
125
128
  return file_import
126
- if async_mode:
129
+ if async_mode and self.code_model.options["tracing"] and self.want_tracing:
127
130
  file_import.add_submodule_import(
128
131
  "azure.core.tracing.decorator_async",
129
132
  "distributed_trace_async",
130
- ImportType.AZURECORE,
133
+ ImportType.SDKCORE,
131
134
  )
132
135
  if (
133
136
  self.code_model.options["models_mode"] == "dpg"
@@ -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 = FileImport()
271
+ file_import = self.init_file_import()
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 = FileImport()
233
+ file_import = self.init_file_import()
234
234
  file_import.add_submodule_import(
235
235
  "typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
236
236
  )
@@ -254,7 +254,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
254
254
 
255
255
  def imports_for_multiapi(self, async_mode: bool, **kwargs: Any) -> FileImport:
256
256
  if self.abstract:
257
- return FileImport()
257
+ return FileImport(self.code_model)
258
258
  file_import = self._imports_shared(async_mode, **kwargs)
259
259
  for param in self.parameters.method:
260
260
  file_import.merge(
@@ -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 = FileImport()
311
+ file_import = self.init_file_import()
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 FileImport()
341
+ return self.init_file_import()
342
342
  file_import = self._imports_shared(async_mode, **kwargs)
343
343
 
344
344
  for param in self.parameters.method:
@@ -379,11 +379,11 @@ class OperationBase( # pylint: disable=too-many-public-methods
379
379
  ]
380
380
  for error in errors:
381
381
  file_import.add_submodule_import(
382
- "azure.core.exceptions", error, ImportType.AZURECORE
382
+ file_import.import_core_exceptions, error, ImportType.SDKCORE
383
383
  )
384
384
  if self.code_model.options["azure_arm"]:
385
385
  file_import.add_submodule_import(
386
- "azure.mgmt.core.exceptions", "ARMErrorFormat", ImportType.AZURECORE
386
+ "azure.mgmt.core.exceptions", "ARMErrorFormat", ImportType.SDKCORE
387
387
  )
388
388
 
389
389
  if self.has_kwargs_to_pop_with_default(
@@ -392,7 +392,9 @@ class OperationBase( # pylint: disable=too-many-public-methods
392
392
  self.parameters.kwargs_to_pop, ParameterLocation.QUERY # type: ignore
393
393
  ):
394
394
  file_import.add_submodule_import(
395
- "azure.core.utils", "case_insensitive_dict", ImportType.AZURECORE
395
+ file_import.import_core_utils,
396
+ "case_insensitive_dict",
397
+ ImportType.SDKCORE,
396
398
  )
397
399
  if self.deprecated:
398
400
  file_import.add_import("warnings", ImportType.STDLIB)
@@ -404,7 +406,9 @@ class OperationBase( # pylint: disable=too-many-public-methods
404
406
  )
405
407
  if self.has_etag:
406
408
  file_import.add_submodule_import(
407
- "azure.core.exceptions", "ResourceModifiedError", ImportType.AZURECORE
409
+ file_import.import_core_exceptions,
410
+ "ResourceModifiedError",
411
+ ImportType.SDKCORE,
408
412
  )
409
413
  if not async_mode:
410
414
  file_import.add_submodule_import(
@@ -418,24 +422,26 @@ class OperationBase( # pylint: disable=too-many-public-methods
418
422
  file_import.add_submodule_import(
419
423
  "azure.core.pipeline.transport",
420
424
  "AsyncHttpResponse",
421
- ImportType.AZURECORE,
425
+ ImportType.SDKCORE,
422
426
  )
423
427
  else:
424
428
  file_import.add_submodule_import(
425
429
  "azure.core.pipeline.transport",
426
430
  "HttpResponse",
427
- ImportType.AZURECORE,
431
+ ImportType.SDKCORE,
428
432
  )
429
433
  else:
430
434
  if async_mode:
431
435
  file_import.add_submodule_import(
432
- "azure.core.rest",
436
+ file_import.import_core_rest,
433
437
  "AsyncHttpResponse",
434
- ImportType.AZURECORE,
438
+ ImportType.SDKCORE,
435
439
  )
436
440
  else:
437
441
  file_import.add_submodule_import(
438
- "azure.core.rest", "HttpResponse", ImportType.AZURECORE
442
+ file_import.import_core_rest,
443
+ "HttpResponse",
444
+ ImportType.SDKCORE,
439
445
  )
440
446
  if (
441
447
  self.code_model.options["builders_visibility"] == "embedded"
@@ -443,10 +449,12 @@ class OperationBase( # pylint: disable=too-many-public-methods
443
449
  ):
444
450
  file_import.merge(self.request_builder.imports())
445
451
  file_import.add_submodule_import(
446
- "azure.core.pipeline", "PipelineResponse", ImportType.AZURECORE
452
+ file_import.import_core_pipeline,
453
+ "PipelineResponse",
454
+ ImportType.SDKCORE,
447
455
  )
448
456
  file_import.add_submodule_import(
449
- "azure.core.rest", "HttpRequest", ImportType.AZURECORE
457
+ file_import.import_core_rest, "HttpRequest", ImportType.SDKCORE
450
458
  )
451
459
  file_import.add_submodule_import(
452
460
  "typing", "Callable", ImportType.STDLIB, TypingSection.CONDITIONAL
@@ -464,7 +472,7 @@ class OperationBase( # pylint: disable=too-many-public-methods
464
472
  file_import.add_submodule_import(
465
473
  "azure.core.tracing.decorator",
466
474
  "distributed_trace",
467
- ImportType.AZURECORE,
475
+ ImportType.SDKCORE,
468
476
  )
469
477
  file_import.merge(
470
478
  self.get_request_builder_import(self.request_builder, async_mode)
@@ -552,11 +560,11 @@ class Operation(OperationBase[Response]):
552
560
  file_import = super().imports(async_mode, **kwargs)
553
561
  if self.abstract:
554
562
  return file_import
555
- if async_mode:
563
+ if async_mode and self.code_model.options["tracing"] and self.want_tracing:
556
564
  file_import.add_submodule_import(
557
565
  "azure.core.tracing.decorator_async",
558
566
  "distributed_trace_async",
559
- ImportType.AZURECORE,
567
+ ImportType.SDKCORE,
560
568
  )
561
569
  if (
562
570
  self.has_response_body
@@ -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 = FileImport()
51
+ file_import = self.init_file_import()
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 = FileImport()
82
+ file_import = self.init_file_import()
83
83
 
84
84
  relative_path = ("..." if async_mode else "..") + (
85
85
  "." if self.client.is_subclient else ""