@autorest/python 6.49.0 → 6.49.2

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 (32) hide show
  1. package/generator/build/lib/pygen/codegen/models/client.py +5 -5
  2. package/generator/build/lib/pygen/codegen/models/credential_types.py +1 -1
  3. package/generator/build/lib/pygen/codegen/models/enum_type.py +1 -1
  4. package/generator/build/lib/pygen/codegen/models/imports.py +2 -3
  5. package/generator/build/lib/pygen/codegen/models/lro_operation.py +1 -1
  6. package/generator/build/lib/pygen/codegen/models/model_type.py +2 -2
  7. package/generator/build/lib/pygen/codegen/models/operation.py +10 -6
  8. package/generator/build/lib/pygen/codegen/models/operation_group.py +1 -1
  9. package/generator/build/lib/pygen/codegen/models/paging_operation.py +7 -3
  10. package/generator/build/lib/pygen/codegen/models/primitive_types.py +1 -1
  11. package/generator/build/lib/pygen/codegen/models/request_builder.py +1 -1
  12. package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +16 -7
  13. package/generator/build/lib/pygen/codegen/serializers/import_serializer.py +4 -31
  14. package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +8 -2
  15. package/generator/component-detection-pip-report.json +6 -6
  16. package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
  17. package/generator/pygen/codegen/models/client.py +5 -5
  18. package/generator/pygen/codegen/models/credential_types.py +1 -1
  19. package/generator/pygen/codegen/models/enum_type.py +1 -1
  20. package/generator/pygen/codegen/models/imports.py +2 -3
  21. package/generator/pygen/codegen/models/lro_operation.py +1 -1
  22. package/generator/pygen/codegen/models/model_type.py +2 -2
  23. package/generator/pygen/codegen/models/operation.py +10 -6
  24. package/generator/pygen/codegen/models/operation_group.py +1 -1
  25. package/generator/pygen/codegen/models/paging_operation.py +7 -3
  26. package/generator/pygen/codegen/models/primitive_types.py +1 -1
  27. package/generator/pygen/codegen/models/request_builder.py +1 -1
  28. package/generator/pygen/codegen/serializers/builder_serializer.py +16 -7
  29. package/generator/pygen/codegen/serializers/import_serializer.py +4 -31
  30. package/generator/pygen/codegen/templates/model_base.py.jinja2 +8 -2
  31. package/package.json +3 -3
  32. package/scripts/__pycache__/venvtools.cpython-310.pyc +0 -0
@@ -247,7 +247,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
247
247
 
248
248
  def imports(self, async_mode: bool, **kwargs) -> FileImport:
249
249
  file_import = FileImport(self.code_model)
250
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
250
+ file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
251
251
  if self.code_model.options["azure-arm"]:
252
252
  file_import.add_submodule_import("azure.mgmt.core", self.pipeline_class(async_mode), ImportType.SDKCORE)
253
253
  else:
@@ -307,20 +307,20 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
307
307
  "rest",
308
308
  "AsyncHttpResponse",
309
309
  ImportType.SDKCORE,
310
- TypingSection.CONDITIONAL,
310
+ TypingSection.REGULAR,
311
311
  )
312
312
  else:
313
313
  file_import.add_submodule_import(
314
314
  "rest",
315
315
  "HttpResponse",
316
316
  ImportType.SDKCORE,
317
- TypingSection.CONDITIONAL,
317
+ TypingSection.REGULAR,
318
318
  )
319
319
  file_import.add_submodule_import(
320
320
  "rest",
321
321
  "HttpRequest",
322
322
  ImportType.SDKCORE,
323
- TypingSection.CONDITIONAL,
323
+ TypingSection.REGULAR,
324
324
  )
325
325
  serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
326
326
  for og in self.operation_groups:
@@ -401,7 +401,7 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
401
401
  "policies",
402
402
  ImportType.SDKCORE,
403
403
  )
404
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
404
+ file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
405
405
  if self.code_model.options.get("package-version"):
406
406
  serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
407
407
  file_import.add_submodule_import(
@@ -213,6 +213,6 @@ class KeyCredentialType(CredentialType[KeyCredentialPolicyType]):
213
213
  "credentials",
214
214
  self.policy.credential_name,
215
215
  ImportType.SDKCORE,
216
- typing_section=TypingSection.CONDITIONAL,
216
+ typing_section=TypingSection.REGULAR,
217
217
  )
218
218
  return file_import
@@ -241,7 +241,7 @@ class EnumType(BaseType):
241
241
  file_import = FileImport(self.code_model)
242
242
  file_import.merge(self.value_type.imports(**kwargs))
243
243
  if self.code_model.options["models-mode"]:
244
- file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL)
244
+ file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.REGULAR)
245
245
 
246
246
  serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
247
247
  relative_path = self.code_model.get_relative_import_path(serialize_namespace, self.client_namespace)
@@ -23,9 +23,8 @@ class ImportType(str, Enum):
23
23
 
24
24
 
25
25
  class TypingSection(str, Enum):
26
- REGULAR = "regular" # this import is always a typing import
27
- CONDITIONAL = "conditional" # is a typing import when we're dealing with files that py2 will use, else regular
28
- TYPING = "typing" # never a typing import
26
+ REGULAR = "regular" # this import is always a regular import
27
+ TYPING = "typing" # this import goes under TYPE_CHECKING
29
28
 
30
29
 
31
30
  class MsrestImportType(Enum):
@@ -138,7 +138,7 @@ class LROOperationBase(OperationBase[LROResponseType]):
138
138
  "_deserialize",
139
139
  ImportType.LOCAL,
140
140
  )
141
- file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL)
141
+ file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.REGULAR)
142
142
  file_import.add_submodule_import("typing", "cast", ImportType.STDLIB)
143
143
  return file_import
144
144
 
@@ -270,7 +270,7 @@ class JSONModelType(ModelType):
270
270
 
271
271
  def imports(self, **kwargs: Any) -> FileImport:
272
272
  file_import = FileImport(self.code_model)
273
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
273
+ file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
274
274
  file_import.define_mutable_mapping_type()
275
275
  if self.is_xml:
276
276
  file_import.add_submodule_import("xml.etree", "ElementTree", ImportType.STDLIB, alias="ET")
@@ -351,7 +351,7 @@ class MsrestModelType(GeneratedModelType):
351
351
 
352
352
  def imports(self, **kwargs: Any) -> FileImport:
353
353
  file_import = super().imports(**kwargs)
354
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
354
+ file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
355
355
  return file_import
356
356
 
357
357
 
@@ -284,6 +284,10 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
284
284
  def need_deserialize(self) -> bool:
285
285
  return any(r.type and not isinstance(r.type, BinaryIteratorType) for r in self.responses)
286
286
 
287
+ @property
288
+ def enable_import_deserialize_xml(self) -> bool:
289
+ return any(xml_serializable(str(r.default_content_type)) for r in self.responses + self.exceptions)
290
+
287
291
  def imports( # pylint: disable=too-many-branches, disable=too-many-statements
288
292
  self, async_mode: bool, **kwargs: Any
289
293
  ) -> FileImport:
@@ -292,11 +296,11 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
292
296
 
293
297
  serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
294
298
  file_import = FileImport(self.code_model)
295
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
299
+ file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
296
300
 
297
301
  response_types = [r.type_annotation(async_mode=async_mode, **kwargs) for r in self.responses if r.type]
298
302
  if len(set(response_types)) > 1:
299
- file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL)
303
+ file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.REGULAR)
300
304
  if self.added_on:
301
305
  serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
302
306
  file_import.add_submodule_import(
@@ -402,9 +406,9 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
402
406
  ImportType.SDKCORE,
403
407
  )
404
408
  file_import.add_submodule_import("rest", "HttpRequest", ImportType.SDKCORE)
405
- file_import.add_submodule_import("typing", "Callable", ImportType.STDLIB, TypingSection.CONDITIONAL)
406
- file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL)
407
- file_import.add_submodule_import("typing", "TypeVar", ImportType.STDLIB, TypingSection.CONDITIONAL)
409
+ file_import.add_submodule_import("typing", "Callable", ImportType.STDLIB, TypingSection.REGULAR)
410
+ file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB, TypingSection.REGULAR)
411
+ file_import.add_submodule_import("typing", "TypeVar", ImportType.STDLIB, TypingSection.REGULAR)
408
412
  if self.code_model.options["tracing"] and self.want_tracing and not async_mode:
409
413
  file_import.add_submodule_import(
410
414
  "azure.core.tracing.decorator",
@@ -443,7 +447,7 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
443
447
  ImportType.LOCAL,
444
448
  )
445
449
  file_import.add_import("json", ImportType.STDLIB)
446
- if any(xml_serializable(str(r.default_content_type)) for r in self.responses + self.exceptions):
450
+ if self.enable_import_deserialize_xml:
447
451
  file_import.add_submodule_import(relative_path, "_deserialize_xml", ImportType.LOCAL)
448
452
  elif self.need_deserialize:
449
453
  file_import.add_submodule_import(relative_path, "_deserialize", ImportType.LOCAL)
@@ -195,7 +195,7 @@ class OperationGroup(BaseModel):
195
195
  )
196
196
  if all(o.abstract for o in self.operations):
197
197
  return file_import
198
- file_import.add_submodule_import("typing", "TypeVar", ImportType.STDLIB, TypingSection.CONDITIONAL)
198
+ file_import.add_submodule_import("typing", "TypeVar", ImportType.STDLIB, TypingSection.REGULAR)
199
199
  file_import.define_mypy_type("T", "TypeVar('T')")
200
200
  type_value = "Optional[Callable[[PipelineResponse[HttpRequest, {}HttpResponse], T, dict[str, Any]], Any]]"
201
201
  file_import.define_mypy_type("ClsType", type_value.format(""), type_value.format("Async"))
@@ -17,6 +17,7 @@ from .parameter_list import ParameterList
17
17
  from .model_type import ModelType
18
18
  from .list_type import ListType
19
19
  from .parameter import Parameter
20
+ from ...utils import xml_serializable
20
21
 
21
22
  if TYPE_CHECKING:
22
23
  from .code_model import CodeModel
@@ -135,6 +136,10 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
135
136
  def has_optional_return_type(self) -> bool:
136
137
  return False
137
138
 
139
+ @property
140
+ def enable_import_deserialize_xml(self):
141
+ return any(xml_serializable(str(r.default_content_type)) for r in self.exceptions)
142
+
138
143
  def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
139
144
  if self.abstract:
140
145
  return FileImport(self.code_model)
@@ -145,11 +150,11 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
145
150
  f"{self.code_model.core_library}.{default_paging_submodule}",
146
151
  "AsyncItemPaged",
147
152
  ImportType.SDKCORE,
148
- TypingSection.CONDITIONAL,
153
+ TypingSection.REGULAR,
149
154
  )
150
155
  else:
151
156
  file_import.add_submodule_import(
152
- f"{self.code_model.core_library}.paging", "ItemPaged", ImportType.SDKCORE, TypingSection.CONDITIONAL
157
+ f"{self.code_model.core_library}.paging", "ItemPaged", ImportType.SDKCORE, TypingSection.REGULAR
153
158
  )
154
159
  if (
155
160
  self.next_request_builder
@@ -185,7 +190,6 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
185
190
  file_import.add_submodule_import(relative_path, "_deserialize", ImportType.LOCAL)
186
191
  if self.is_xml_paging:
187
192
  file_import.add_submodule_import("xml.etree", "ElementTree", ImportType.STDLIB, alias="ET")
188
- file_import.add_submodule_import(relative_path, "_convert_element", ImportType.LOCAL)
189
193
  return file_import
190
194
 
191
195
 
@@ -139,7 +139,7 @@ class AnyType(PrimitiveType):
139
139
 
140
140
  def imports(self, **kwargs: Any) -> FileImport:
141
141
  file_import = FileImport(self.code_model)
142
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
142
+ file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
143
143
  return file_import
144
144
 
145
145
  @property
@@ -120,7 +120,7 @@ class RequestBuilderBase(BaseBuilder[ParameterListType, Sequence["RequestBuilder
120
120
  "case_insensitive_dict",
121
121
  ImportType.SDKCORE,
122
122
  )
123
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, typing_section=TypingSection.CONDITIONAL)
123
+ file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, typing_section=TypingSection.REGULAR)
124
124
  file_import.add_msrest_import(
125
125
  serialize_namespace=kwargs.get("serialize_namespace", self.code_model.namespace),
126
126
  msrest_import_type=MsrestImportType.Serializer,
@@ -564,7 +564,7 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
564
564
  def make_pipeline_call(self, builder: OperationType) -> list[str]:
565
565
  retval = []
566
566
  type_ignore = self.async_mode and builder.group_name == "" # is in a mixin
567
- if builder.stream_value is True and not self.code_model.options["version-tolerant"]:
567
+ if builder.stream_value:
568
568
  retval.append("_decompress = kwargs.pop('decompress', True)")
569
569
  pylint_disable = " # pylint: disable=protected-access" if self.code_model.is_azure_flavor else ""
570
570
  retval.extend(
@@ -973,7 +973,7 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
973
973
  else:
974
974
  stream_logic = False
975
975
  if self.code_model.options["version-tolerant"]:
976
- deserialized = "response.iter_bytes()"
976
+ deserialized = "response.iter_bytes() if _decompress else response.iter_raw()"
977
977
  else:
978
978
  deserialized = (
979
979
  f"response.stream_download(self._client.{self.pipeline_name}, decompress=_decompress)"
@@ -1020,7 +1020,7 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
1020
1020
  if len(deserialize_code) > 0:
1021
1021
  if builder.expose_stream_keyword and stream_logic:
1022
1022
  retval.append("if _stream:")
1023
- retval.append(" deserialized = response.iter_bytes()")
1023
+ retval.append(" deserialized = response.iter_bytes() if _decompress else response.iter_raw()")
1024
1024
  retval.append("else:")
1025
1025
  retval.extend([f" {dc}" for dc in deserialize_code])
1026
1026
  else:
@@ -1418,15 +1418,24 @@ class _PagingOperationSerializer(_OperationSerializer[PagingOperationType]):
1418
1418
  access = (
1419
1419
  "".join([f'.get("{i}", {{}})' for i in item_name_array[:-1]]) + f'.get("{item_name_array[-1]}", [])'
1420
1420
  )
1421
- list_of_elem_deserialized = ""
1421
+ pylint_disable = ""
1422
1422
  if self.code_model.options["models-mode"] == "dpg":
1423
1423
  item_type = builder.item_type.type_annotation(
1424
1424
  is_operation_file=True, serialize_namespace=self.serialize_namespace
1425
1425
  )
1426
- list_of_elem_deserialized = f"_deserialize({item_type}, deserialized{access})"
1426
+ pylint_disable = (
1427
+ " # pylint: disable=protected-access" if getattr(builder.item_type, "internal", False) else ""
1428
+ )
1429
+ list_of_elem_deserialized = [
1430
+ "_deserialize(",
1431
+ f"{item_type},{pylint_disable}",
1432
+ f"deserialized{access},",
1433
+ ")",
1434
+ ]
1427
1435
  else:
1428
- list_of_elem_deserialized = f"deserialized{access}"
1429
- retval.append(f" list_of_elem = {list_of_elem_deserialized}")
1436
+ list_of_elem_deserialized = [f"deserialized{access}"]
1437
+ list_of_elem_deserialized_str = "\n ".join(list_of_elem_deserialized)
1438
+ retval.append(f" list_of_elem = {list_of_elem_deserialized_str}")
1430
1439
  retval.append(" if cls:")
1431
1440
  retval.append(" list_of_elem = cls(list_of_elem) # type: ignore")
1432
1441
 
@@ -72,29 +72,8 @@ class FileImportSerializer:
72
72
  self.file_import = file_import
73
73
  self.async_mode = async_mode
74
74
 
75
- def _get_imports_list(self, baseline_typing_section: TypingSection, add_conditional_typing: bool):
76
- # If this is a python 3 file, our regular imports include the CONDITIONAL category
77
- # If this is not a python 3 file, our typing imports include the CONDITIONAL category
78
-
79
- # Get imports that already match the baseline_typing_section
80
- result = list(self.file_import.get_imports_from_section(baseline_typing_section))
81
-
82
- if add_conditional_typing:
83
- # Get conditional imports and create new ImportModel instances with modified typing_section
84
- conditional_imports = self.file_import.get_imports_from_section(TypingSection.CONDITIONAL)
85
- for i in conditional_imports:
86
- # Create a new ImportModel with the baseline_typing_section instead of CONDITIONAL
87
- result.append(
88
- ImportModel(
89
- typing_section=baseline_typing_section,
90
- import_type=i.import_type,
91
- module_name=i.module_name,
92
- submodule_name=i.submodule_name,
93
- alias=i.alias,
94
- version_modules=i.version_modules,
95
- )
96
- )
97
- return result
75
+ def _get_imports_list(self, typing_section: TypingSection):
76
+ return list(self.file_import.get_imports_from_section(typing_section))
98
77
 
99
78
  def _add_type_checking_import(self):
100
79
  if any(self.file_import.get_imports_from_section(TypingSection.TYPING)):
@@ -117,19 +96,13 @@ class FileImportSerializer:
117
96
  def __str__(self) -> str:
118
97
  self._add_type_checking_import()
119
98
  regular_imports = ""
120
- regular_imports_list = self._get_imports_list(
121
- baseline_typing_section=TypingSection.REGULAR,
122
- add_conditional_typing=True,
123
- )
99
+ regular_imports_list = self._get_imports_list(TypingSection.REGULAR)
124
100
 
125
101
  if regular_imports_list:
126
102
  regular_imports = "\n\n".join(_get_import_clauses(regular_imports_list, "\n"))
127
103
 
128
104
  typing_imports = ""
129
- typing_imports_list = self._get_imports_list(
130
- baseline_typing_section=TypingSection.TYPING,
131
- add_conditional_typing=False,
132
- )
105
+ typing_imports_list = self._get_imports_list(TypingSection.TYPING)
133
106
  if typing_imports_list:
134
107
  typing_imports += "\n\nif TYPE_CHECKING:\n "
135
108
  typing_imports += "\n\n ".join(_get_import_clauses(typing_imports_list, "\n "))
@@ -527,6 +527,8 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]):
527
527
  return self._data.setdefault(key, default)
528
528
 
529
529
  def __eq__(self, other: typing.Any) -> bool:
530
+ if isinstance(other, _MyMutableMapping):
531
+ return self._data == other._data
530
532
  try:
531
533
  other_model = self.__class__(other)
532
534
  except Exception:
@@ -1020,16 +1022,20 @@ def _deserialize_with_callable(
1020
1022
  return float(value.text) if value.text else None
1021
1023
  if deserializer is bool:
1022
1024
  return value.text == "true" if value.text else None
1025
+ if deserializer and deserializer in _DESERIALIZE_MAPPING.values():
1026
+ return deserializer(value.text) if value.text else None
1027
+ if deserializer and deserializer in _DESERIALIZE_MAPPING_WITHFORMAT.values():
1028
+ return deserializer(value.text) if value.text else None
1023
1029
  if deserializer is None:
1024
1030
  return value
1025
1031
  if deserializer in [int, float, bool]:
1026
1032
  return deserializer(value)
1027
1033
  if isinstance(deserializer, CaseInsensitiveEnumMeta):
1028
1034
  try:
1029
- return deserializer(value)
1035
+ return deserializer(value.text if isinstance(value, ET.Element) else value)
1030
1036
  except ValueError:
1031
1037
  # for unknown value, return raw value
1032
- return value
1038
+ return value.text if isinstance(value, ET.Element) else value
1033
1039
  if isinstance(deserializer, type) and issubclass(deserializer, Model):
1034
1040
  return deserializer._deserialize(value, [])
1035
1041
  return typing.cast(typing.Callable[[typing.Any], typing.Any], deserializer)(value)
@@ -4,11 +4,11 @@
4
4
  "install": [
5
5
  {
6
6
  "download_info": {
7
- "url": "https://files.pythonhosted.org/packages/94/b8/f1f62a5e3c0ad2ff1d189590bfa4c46b4f3b6e49cef6f26c6ee4e575394d/setuptools-80.10.2-py3-none-any.whl",
7
+ "url": "https://files.pythonhosted.org/packages/e1/c6/76dc613121b793286a3f91621d7b75a2b493e0390ddca50f11993eadf192/setuptools-82.0.0-py3-none-any.whl",
8
8
  "archive_info": {
9
- "hash": "sha256=95b30ddfb717250edb492926c92b5221f7ef3fbcc2b07579bcd4a27da21d0173",
9
+ "hash": "sha256=70b18734b607bd1da571d097d236cfcfacaf01de45717d59e6e04b96877532e0",
10
10
  "hashes": {
11
- "sha256": "95b30ddfb717250edb492926c92b5221f7ef3fbcc2b07579bcd4a27da21d0173"
11
+ "sha256": "70b18734b607bd1da571d097d236cfcfacaf01de45717d59e6e04b96877532e0"
12
12
  }
13
13
  }
14
14
  },
@@ -18,7 +18,7 @@
18
18
  "metadata": {
19
19
  "metadata_version": "2.4",
20
20
  "name": "setuptools",
21
- "version": "80.10.2",
21
+ "version": "82.0.0",
22
22
  "dynamic": [
23
23
  "license-file"
24
24
  ],
@@ -93,11 +93,11 @@
93
93
  "more_itertools; extra == \"core\"",
94
94
  "pytest-checkdocs>=2.4; extra == \"check\"",
95
95
  "pytest-ruff>=0.2.1; sys_platform != \"cygwin\" and extra == \"check\"",
96
- "ruff>=0.8.0; sys_platform != \"cygwin\" and extra == \"check\"",
96
+ "ruff>=0.13.0; sys_platform != \"cygwin\" and extra == \"check\"",
97
97
  "pytest-cov; extra == \"cover\"",
98
98
  "pytest-enabler>=2.2; extra == \"enabler\"",
99
99
  "pytest-mypy; extra == \"type\"",
100
- "mypy==1.14.*; extra == \"type\"",
100
+ "mypy==1.18.*; extra == \"type\"",
101
101
  "importlib_metadata>=7.0.2; python_version < \"3.10\" and extra == \"type\"",
102
102
  "jaraco.develop>=7.21; sys_platform != \"cygwin\" and extra == \"type\""
103
103
  ],
@@ -247,7 +247,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
247
247
 
248
248
  def imports(self, async_mode: bool, **kwargs) -> FileImport:
249
249
  file_import = FileImport(self.code_model)
250
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
250
+ file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
251
251
  if self.code_model.options["azure-arm"]:
252
252
  file_import.add_submodule_import("azure.mgmt.core", self.pipeline_class(async_mode), ImportType.SDKCORE)
253
253
  else:
@@ -307,20 +307,20 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
307
307
  "rest",
308
308
  "AsyncHttpResponse",
309
309
  ImportType.SDKCORE,
310
- TypingSection.CONDITIONAL,
310
+ TypingSection.REGULAR,
311
311
  )
312
312
  else:
313
313
  file_import.add_submodule_import(
314
314
  "rest",
315
315
  "HttpResponse",
316
316
  ImportType.SDKCORE,
317
- TypingSection.CONDITIONAL,
317
+ TypingSection.REGULAR,
318
318
  )
319
319
  file_import.add_submodule_import(
320
320
  "rest",
321
321
  "HttpRequest",
322
322
  ImportType.SDKCORE,
323
- TypingSection.CONDITIONAL,
323
+ TypingSection.REGULAR,
324
324
  )
325
325
  serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
326
326
  for og in self.operation_groups:
@@ -401,7 +401,7 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
401
401
  "policies",
402
402
  ImportType.SDKCORE,
403
403
  )
404
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
404
+ file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
405
405
  if self.code_model.options.get("package-version"):
406
406
  serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
407
407
  file_import.add_submodule_import(
@@ -213,6 +213,6 @@ class KeyCredentialType(CredentialType[KeyCredentialPolicyType]):
213
213
  "credentials",
214
214
  self.policy.credential_name,
215
215
  ImportType.SDKCORE,
216
- typing_section=TypingSection.CONDITIONAL,
216
+ typing_section=TypingSection.REGULAR,
217
217
  )
218
218
  return file_import
@@ -241,7 +241,7 @@ class EnumType(BaseType):
241
241
  file_import = FileImport(self.code_model)
242
242
  file_import.merge(self.value_type.imports(**kwargs))
243
243
  if self.code_model.options["models-mode"]:
244
- file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL)
244
+ file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.REGULAR)
245
245
 
246
246
  serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
247
247
  relative_path = self.code_model.get_relative_import_path(serialize_namespace, self.client_namespace)
@@ -23,9 +23,8 @@ class ImportType(str, Enum):
23
23
 
24
24
 
25
25
  class TypingSection(str, Enum):
26
- REGULAR = "regular" # this import is always a typing import
27
- CONDITIONAL = "conditional" # is a typing import when we're dealing with files that py2 will use, else regular
28
- TYPING = "typing" # never a typing import
26
+ REGULAR = "regular" # this import is always a regular import
27
+ TYPING = "typing" # this import goes under TYPE_CHECKING
29
28
 
30
29
 
31
30
  class MsrestImportType(Enum):
@@ -138,7 +138,7 @@ class LROOperationBase(OperationBase[LROResponseType]):
138
138
  "_deserialize",
139
139
  ImportType.LOCAL,
140
140
  )
141
- file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL)
141
+ file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.REGULAR)
142
142
  file_import.add_submodule_import("typing", "cast", ImportType.STDLIB)
143
143
  return file_import
144
144
 
@@ -270,7 +270,7 @@ class JSONModelType(ModelType):
270
270
 
271
271
  def imports(self, **kwargs: Any) -> FileImport:
272
272
  file_import = FileImport(self.code_model)
273
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
273
+ file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
274
274
  file_import.define_mutable_mapping_type()
275
275
  if self.is_xml:
276
276
  file_import.add_submodule_import("xml.etree", "ElementTree", ImportType.STDLIB, alias="ET")
@@ -351,7 +351,7 @@ class MsrestModelType(GeneratedModelType):
351
351
 
352
352
  def imports(self, **kwargs: Any) -> FileImport:
353
353
  file_import = super().imports(**kwargs)
354
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
354
+ file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
355
355
  return file_import
356
356
 
357
357
 
@@ -284,6 +284,10 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
284
284
  def need_deserialize(self) -> bool:
285
285
  return any(r.type and not isinstance(r.type, BinaryIteratorType) for r in self.responses)
286
286
 
287
+ @property
288
+ def enable_import_deserialize_xml(self) -> bool:
289
+ return any(xml_serializable(str(r.default_content_type)) for r in self.responses + self.exceptions)
290
+
287
291
  def imports( # pylint: disable=too-many-branches, disable=too-many-statements
288
292
  self, async_mode: bool, **kwargs: Any
289
293
  ) -> FileImport:
@@ -292,11 +296,11 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
292
296
 
293
297
  serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
294
298
  file_import = FileImport(self.code_model)
295
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
299
+ file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
296
300
 
297
301
  response_types = [r.type_annotation(async_mode=async_mode, **kwargs) for r in self.responses if r.type]
298
302
  if len(set(response_types)) > 1:
299
- file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL)
303
+ file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.REGULAR)
300
304
  if self.added_on:
301
305
  serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
302
306
  file_import.add_submodule_import(
@@ -402,9 +406,9 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
402
406
  ImportType.SDKCORE,
403
407
  )
404
408
  file_import.add_submodule_import("rest", "HttpRequest", ImportType.SDKCORE)
405
- file_import.add_submodule_import("typing", "Callable", ImportType.STDLIB, TypingSection.CONDITIONAL)
406
- file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL)
407
- file_import.add_submodule_import("typing", "TypeVar", ImportType.STDLIB, TypingSection.CONDITIONAL)
409
+ file_import.add_submodule_import("typing", "Callable", ImportType.STDLIB, TypingSection.REGULAR)
410
+ file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB, TypingSection.REGULAR)
411
+ file_import.add_submodule_import("typing", "TypeVar", ImportType.STDLIB, TypingSection.REGULAR)
408
412
  if self.code_model.options["tracing"] and self.want_tracing and not async_mode:
409
413
  file_import.add_submodule_import(
410
414
  "azure.core.tracing.decorator",
@@ -443,7 +447,7 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
443
447
  ImportType.LOCAL,
444
448
  )
445
449
  file_import.add_import("json", ImportType.STDLIB)
446
- if any(xml_serializable(str(r.default_content_type)) for r in self.responses + self.exceptions):
450
+ if self.enable_import_deserialize_xml:
447
451
  file_import.add_submodule_import(relative_path, "_deserialize_xml", ImportType.LOCAL)
448
452
  elif self.need_deserialize:
449
453
  file_import.add_submodule_import(relative_path, "_deserialize", ImportType.LOCAL)
@@ -195,7 +195,7 @@ class OperationGroup(BaseModel):
195
195
  )
196
196
  if all(o.abstract for o in self.operations):
197
197
  return file_import
198
- file_import.add_submodule_import("typing", "TypeVar", ImportType.STDLIB, TypingSection.CONDITIONAL)
198
+ file_import.add_submodule_import("typing", "TypeVar", ImportType.STDLIB, TypingSection.REGULAR)
199
199
  file_import.define_mypy_type("T", "TypeVar('T')")
200
200
  type_value = "Optional[Callable[[PipelineResponse[HttpRequest, {}HttpResponse], T, dict[str, Any]], Any]]"
201
201
  file_import.define_mypy_type("ClsType", type_value.format(""), type_value.format("Async"))
@@ -17,6 +17,7 @@ from .parameter_list import ParameterList
17
17
  from .model_type import ModelType
18
18
  from .list_type import ListType
19
19
  from .parameter import Parameter
20
+ from ...utils import xml_serializable
20
21
 
21
22
  if TYPE_CHECKING:
22
23
  from .code_model import CodeModel
@@ -135,6 +136,10 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
135
136
  def has_optional_return_type(self) -> bool:
136
137
  return False
137
138
 
139
+ @property
140
+ def enable_import_deserialize_xml(self):
141
+ return any(xml_serializable(str(r.default_content_type)) for r in self.exceptions)
142
+
138
143
  def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
139
144
  if self.abstract:
140
145
  return FileImport(self.code_model)
@@ -145,11 +150,11 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
145
150
  f"{self.code_model.core_library}.{default_paging_submodule}",
146
151
  "AsyncItemPaged",
147
152
  ImportType.SDKCORE,
148
- TypingSection.CONDITIONAL,
153
+ TypingSection.REGULAR,
149
154
  )
150
155
  else:
151
156
  file_import.add_submodule_import(
152
- f"{self.code_model.core_library}.paging", "ItemPaged", ImportType.SDKCORE, TypingSection.CONDITIONAL
157
+ f"{self.code_model.core_library}.paging", "ItemPaged", ImportType.SDKCORE, TypingSection.REGULAR
153
158
  )
154
159
  if (
155
160
  self.next_request_builder
@@ -185,7 +190,6 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
185
190
  file_import.add_submodule_import(relative_path, "_deserialize", ImportType.LOCAL)
186
191
  if self.is_xml_paging:
187
192
  file_import.add_submodule_import("xml.etree", "ElementTree", ImportType.STDLIB, alias="ET")
188
- file_import.add_submodule_import(relative_path, "_convert_element", ImportType.LOCAL)
189
193
  return file_import
190
194
 
191
195
 
@@ -139,7 +139,7 @@ class AnyType(PrimitiveType):
139
139
 
140
140
  def imports(self, **kwargs: Any) -> FileImport:
141
141
  file_import = FileImport(self.code_model)
142
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
142
+ file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
143
143
  return file_import
144
144
 
145
145
  @property
@@ -120,7 +120,7 @@ class RequestBuilderBase(BaseBuilder[ParameterListType, Sequence["RequestBuilder
120
120
  "case_insensitive_dict",
121
121
  ImportType.SDKCORE,
122
122
  )
123
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, typing_section=TypingSection.CONDITIONAL)
123
+ file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, typing_section=TypingSection.REGULAR)
124
124
  file_import.add_msrest_import(
125
125
  serialize_namespace=kwargs.get("serialize_namespace", self.code_model.namespace),
126
126
  msrest_import_type=MsrestImportType.Serializer,
@@ -564,7 +564,7 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
564
564
  def make_pipeline_call(self, builder: OperationType) -> list[str]:
565
565
  retval = []
566
566
  type_ignore = self.async_mode and builder.group_name == "" # is in a mixin
567
- if builder.stream_value is True and not self.code_model.options["version-tolerant"]:
567
+ if builder.stream_value:
568
568
  retval.append("_decompress = kwargs.pop('decompress', True)")
569
569
  pylint_disable = " # pylint: disable=protected-access" if self.code_model.is_azure_flavor else ""
570
570
  retval.extend(
@@ -973,7 +973,7 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
973
973
  else:
974
974
  stream_logic = False
975
975
  if self.code_model.options["version-tolerant"]:
976
- deserialized = "response.iter_bytes()"
976
+ deserialized = "response.iter_bytes() if _decompress else response.iter_raw()"
977
977
  else:
978
978
  deserialized = (
979
979
  f"response.stream_download(self._client.{self.pipeline_name}, decompress=_decompress)"
@@ -1020,7 +1020,7 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
1020
1020
  if len(deserialize_code) > 0:
1021
1021
  if builder.expose_stream_keyword and stream_logic:
1022
1022
  retval.append("if _stream:")
1023
- retval.append(" deserialized = response.iter_bytes()")
1023
+ retval.append(" deserialized = response.iter_bytes() if _decompress else response.iter_raw()")
1024
1024
  retval.append("else:")
1025
1025
  retval.extend([f" {dc}" for dc in deserialize_code])
1026
1026
  else:
@@ -1418,15 +1418,24 @@ class _PagingOperationSerializer(_OperationSerializer[PagingOperationType]):
1418
1418
  access = (
1419
1419
  "".join([f'.get("{i}", {{}})' for i in item_name_array[:-1]]) + f'.get("{item_name_array[-1]}", [])'
1420
1420
  )
1421
- list_of_elem_deserialized = ""
1421
+ pylint_disable = ""
1422
1422
  if self.code_model.options["models-mode"] == "dpg":
1423
1423
  item_type = builder.item_type.type_annotation(
1424
1424
  is_operation_file=True, serialize_namespace=self.serialize_namespace
1425
1425
  )
1426
- list_of_elem_deserialized = f"_deserialize({item_type}, deserialized{access})"
1426
+ pylint_disable = (
1427
+ " # pylint: disable=protected-access" if getattr(builder.item_type, "internal", False) else ""
1428
+ )
1429
+ list_of_elem_deserialized = [
1430
+ "_deserialize(",
1431
+ f"{item_type},{pylint_disable}",
1432
+ f"deserialized{access},",
1433
+ ")",
1434
+ ]
1427
1435
  else:
1428
- list_of_elem_deserialized = f"deserialized{access}"
1429
- retval.append(f" list_of_elem = {list_of_elem_deserialized}")
1436
+ list_of_elem_deserialized = [f"deserialized{access}"]
1437
+ list_of_elem_deserialized_str = "\n ".join(list_of_elem_deserialized)
1438
+ retval.append(f" list_of_elem = {list_of_elem_deserialized_str}")
1430
1439
  retval.append(" if cls:")
1431
1440
  retval.append(" list_of_elem = cls(list_of_elem) # type: ignore")
1432
1441
 
@@ -72,29 +72,8 @@ class FileImportSerializer:
72
72
  self.file_import = file_import
73
73
  self.async_mode = async_mode
74
74
 
75
- def _get_imports_list(self, baseline_typing_section: TypingSection, add_conditional_typing: bool):
76
- # If this is a python 3 file, our regular imports include the CONDITIONAL category
77
- # If this is not a python 3 file, our typing imports include the CONDITIONAL category
78
-
79
- # Get imports that already match the baseline_typing_section
80
- result = list(self.file_import.get_imports_from_section(baseline_typing_section))
81
-
82
- if add_conditional_typing:
83
- # Get conditional imports and create new ImportModel instances with modified typing_section
84
- conditional_imports = self.file_import.get_imports_from_section(TypingSection.CONDITIONAL)
85
- for i in conditional_imports:
86
- # Create a new ImportModel with the baseline_typing_section instead of CONDITIONAL
87
- result.append(
88
- ImportModel(
89
- typing_section=baseline_typing_section,
90
- import_type=i.import_type,
91
- module_name=i.module_name,
92
- submodule_name=i.submodule_name,
93
- alias=i.alias,
94
- version_modules=i.version_modules,
95
- )
96
- )
97
- return result
75
+ def _get_imports_list(self, typing_section: TypingSection):
76
+ return list(self.file_import.get_imports_from_section(typing_section))
98
77
 
99
78
  def _add_type_checking_import(self):
100
79
  if any(self.file_import.get_imports_from_section(TypingSection.TYPING)):
@@ -117,19 +96,13 @@ class FileImportSerializer:
117
96
  def __str__(self) -> str:
118
97
  self._add_type_checking_import()
119
98
  regular_imports = ""
120
- regular_imports_list = self._get_imports_list(
121
- baseline_typing_section=TypingSection.REGULAR,
122
- add_conditional_typing=True,
123
- )
99
+ regular_imports_list = self._get_imports_list(TypingSection.REGULAR)
124
100
 
125
101
  if regular_imports_list:
126
102
  regular_imports = "\n\n".join(_get_import_clauses(regular_imports_list, "\n"))
127
103
 
128
104
  typing_imports = ""
129
- typing_imports_list = self._get_imports_list(
130
- baseline_typing_section=TypingSection.TYPING,
131
- add_conditional_typing=False,
132
- )
105
+ typing_imports_list = self._get_imports_list(TypingSection.TYPING)
133
106
  if typing_imports_list:
134
107
  typing_imports += "\n\nif TYPE_CHECKING:\n "
135
108
  typing_imports += "\n\n ".join(_get_import_clauses(typing_imports_list, "\n "))
@@ -527,6 +527,8 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]):
527
527
  return self._data.setdefault(key, default)
528
528
 
529
529
  def __eq__(self, other: typing.Any) -> bool:
530
+ if isinstance(other, _MyMutableMapping):
531
+ return self._data == other._data
530
532
  try:
531
533
  other_model = self.__class__(other)
532
534
  except Exception:
@@ -1020,16 +1022,20 @@ def _deserialize_with_callable(
1020
1022
  return float(value.text) if value.text else None
1021
1023
  if deserializer is bool:
1022
1024
  return value.text == "true" if value.text else None
1025
+ if deserializer and deserializer in _DESERIALIZE_MAPPING.values():
1026
+ return deserializer(value.text) if value.text else None
1027
+ if deserializer and deserializer in _DESERIALIZE_MAPPING_WITHFORMAT.values():
1028
+ return deserializer(value.text) if value.text else None
1023
1029
  if deserializer is None:
1024
1030
  return value
1025
1031
  if deserializer in [int, float, bool]:
1026
1032
  return deserializer(value)
1027
1033
  if isinstance(deserializer, CaseInsensitiveEnumMeta):
1028
1034
  try:
1029
- return deserializer(value)
1035
+ return deserializer(value.text if isinstance(value, ET.Element) else value)
1030
1036
  except ValueError:
1031
1037
  # for unknown value, return raw value
1032
- return value
1038
+ return value.text if isinstance(value, ET.Element) else value
1033
1039
  if isinstance(deserializer, type) and issubclass(deserializer, Model):
1034
1040
  return deserializer._deserialize(value, [])
1035
1041
  return typing.cast(typing.Callable[[typing.Any], typing.Any], deserializer)(value)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.49.0",
3
+ "version": "6.49.2",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -19,10 +19,10 @@
19
19
  },
20
20
  "homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
21
21
  "dependencies": {
22
- "@typespec/http-client-python": "~0.27.0",
22
+ "@typespec/http-client-python": "~0.27.2",
23
23
  "@autorest/system-requirements": "~1.0.2",
24
24
  "fs-extra": "~11.2.0",
25
- "tsx": "~4.19.1"
25
+ "tsx": "^4.21.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@microsoft.azure/autorest.testserver": "^3.3.50",