@autorest/python 6.49.1 → 6.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) 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 +5 -5
  8. package/generator/build/lib/pygen/codegen/models/operation_group.py +1 -1
  9. package/generator/build/lib/pygen/codegen/models/paging_operation.py +2 -2
  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 +14 -4
  15. package/generator/build/lib/pygen/preprocess/__init__.py +9 -21
  16. package/generator/build/lib/pygen/preprocess/python_mappings.py +0 -2
  17. package/generator/component-detection-pip-report.json +5 -6
  18. package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
  19. package/generator/pygen/codegen/models/client.py +5 -5
  20. package/generator/pygen/codegen/models/credential_types.py +1 -1
  21. package/generator/pygen/codegen/models/enum_type.py +1 -1
  22. package/generator/pygen/codegen/models/imports.py +2 -3
  23. package/generator/pygen/codegen/models/lro_operation.py +1 -1
  24. package/generator/pygen/codegen/models/model_type.py +2 -2
  25. package/generator/pygen/codegen/models/operation.py +5 -5
  26. package/generator/pygen/codegen/models/operation_group.py +1 -1
  27. package/generator/pygen/codegen/models/paging_operation.py +2 -2
  28. package/generator/pygen/codegen/models/primitive_types.py +1 -1
  29. package/generator/pygen/codegen/models/request_builder.py +1 -1
  30. package/generator/pygen/codegen/serializers/builder_serializer.py +16 -7
  31. package/generator/pygen/codegen/serializers/import_serializer.py +4 -31
  32. package/generator/pygen/codegen/templates/model_base.py.jinja2 +14 -4
  33. package/generator/pygen/preprocess/__init__.py +9 -21
  34. package/generator/pygen/preprocess/python_mappings.py +0 -2
  35. package/package.json +3 -3
  36. 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
 
@@ -296,11 +296,11 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
296
296
 
297
297
  serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
298
298
  file_import = FileImport(self.code_model)
299
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
299
+ file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
300
300
 
301
301
  response_types = [r.type_annotation(async_mode=async_mode, **kwargs) for r in self.responses if r.type]
302
302
  if len(set(response_types)) > 1:
303
- file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL)
303
+ file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.REGULAR)
304
304
  if self.added_on:
305
305
  serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
306
306
  file_import.add_submodule_import(
@@ -406,9 +406,9 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
406
406
  ImportType.SDKCORE,
407
407
  )
408
408
  file_import.add_submodule_import("rest", "HttpRequest", ImportType.SDKCORE)
409
- file_import.add_submodule_import("typing", "Callable", ImportType.STDLIB, TypingSection.CONDITIONAL)
410
- file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL)
411
- 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)
412
412
  if self.code_model.options["tracing"] and self.want_tracing and not async_mode:
413
413
  file_import.add_submodule_import(
414
414
  "azure.core.tracing.decorator",
@@ -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"))
@@ -150,11 +150,11 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
150
150
  f"{self.code_model.core_library}.{default_paging_submodule}",
151
151
  "AsyncItemPaged",
152
152
  ImportType.SDKCORE,
153
- TypingSection.CONDITIONAL,
153
+ TypingSection.REGULAR,
154
154
  )
155
155
  else:
156
156
  file_import.add_submodule_import(
157
- 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
158
158
  )
159
159
  if (
160
160
  self.next_request_builder
@@ -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:
@@ -650,6 +652,9 @@ class Model(_MyMutableMapping):
650
652
  if len(items) > 0:
651
653
  existed_attr_keys.append(xml_name)
652
654
  dict_to_pass[rf._rest_name] = _deserialize(rf._type, items)
655
+ elif not rf._is_optional:
656
+ existed_attr_keys.append(xml_name)
657
+ dict_to_pass[rf._rest_name] = []
653
658
  continue
654
659
 
655
660
  # text element is primitive type
@@ -928,6 +933,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur
928
933
  # is it optional?
929
934
  try:
930
935
  if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore
936
+ if rf:
937
+ rf._is_optional = True
931
938
  if len(annotation.__args__) <= 2: # pyright: ignore
932
939
  if_obj_deserializer = _get_deserialize_callable_from_annotation(
933
940
  next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore
@@ -1020,16 +1027,20 @@ def _deserialize_with_callable(
1020
1027
  return float(value.text) if value.text else None
1021
1028
  if deserializer is bool:
1022
1029
  return value.text == "true" if value.text else None
1030
+ if deserializer and deserializer in _DESERIALIZE_MAPPING.values():
1031
+ return deserializer(value.text) if value.text else None
1032
+ if deserializer and deserializer in _DESERIALIZE_MAPPING_WITHFORMAT.values():
1033
+ return deserializer(value.text) if value.text else None
1023
1034
  if deserializer is None:
1024
1035
  return value
1025
1036
  if deserializer in [int, float, bool]:
1026
1037
  return deserializer(value)
1027
1038
  if isinstance(deserializer, CaseInsensitiveEnumMeta):
1028
1039
  try:
1029
- return deserializer(value)
1040
+ return deserializer(value.text if isinstance(value, ET.Element) else value)
1030
1041
  except ValueError:
1031
1042
  # for unknown value, return raw value
1032
- return value
1043
+ return value.text if isinstance(value, ET.Element) else value
1033
1044
  if isinstance(deserializer, type) and issubclass(deserializer, Model):
1034
1045
  return deserializer._deserialize(value, [])
1035
1046
  return typing.cast(typing.Callable[[typing.Any], typing.Any], deserializer)(value)
@@ -1084,9 +1095,7 @@ def _failsafe_deserialize_xml(
1084
1095
  return None
1085
1096
 
1086
1097
 
1087
- {% if code_model.has_padded_model_property %}
1088
1098
  # pylint: disable=too-many-instance-attributes
1089
- {% endif %}
1090
1099
  class _RestField:
1091
1100
  def __init__(
1092
1101
  self,
@@ -1109,6 +1118,7 @@ class _RestField:
1109
1118
  self._is_discriminator = is_discriminator
1110
1119
  self._visibility = visibility
1111
1120
  self._is_model = False
1121
+ self._is_optional = False
1112
1122
  self._default = default
1113
1123
  self._format = format
1114
1124
  self._is_multipart_file_input = is_multipart_file_input
@@ -4,6 +4,7 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  """The preprocessing autorest plugin."""
7
+
7
8
  import copy
8
9
  from typing import Callable, Any, Optional
9
10
 
@@ -21,7 +22,6 @@ from ..utils import (
21
22
  get_body_type_for_description,
22
23
  JSON_REGEXP,
23
24
  KNOWN_TYPES,
24
- update_enum_value,
25
25
  )
26
26
 
27
27
 
@@ -267,30 +267,18 @@ class PreProcessPlugin(YamlUpdatePlugin):
267
267
  add_redefined_builtin_info(property["clientName"], property)
268
268
  if type.get("name"):
269
269
  pad_type = PadType.MODEL if type["type"] == "model" else PadType.ENUM_CLASS
270
- name = self.pad_reserved_words(type["name"], pad_type, type)
271
- type["name"] = name[0].upper() + name[1:]
270
+ if type["type"] != "enumvalue":
271
+ name = self.pad_reserved_words(type["name"], pad_type, type)
272
+ type["name"] = name[0].upper() + name[1:]
272
273
  type["description"] = update_description(type.get("description", ""), type["name"])
273
274
  type["snakeCaseName"] = to_snake_case(type["name"])
274
275
  if type.get("values"):
275
- # we're enums
276
- values_to_add = []
276
+ # we're enums - enum values are UPPER_CASE so no padding needed for reserved words
277
277
  for value in type["values"]:
278
- padded_name = self.pad_reserved_words(value["name"].lower(), PadType.ENUM_VALUE, value).upper()
279
- if self.version_tolerant:
280
- if padded_name[0] in "0123456789":
281
- padded_name = "ENUM_" + padded_name
282
- value["name"] = padded_name
283
- else:
284
- if value["name"] != padded_name:
285
- values_to_add.append(
286
- update_enum_value(
287
- name=padded_name,
288
- value=value["value"],
289
- description=value["description"],
290
- enum_type=value["enumType"],
291
- )
292
- )
293
- type["values"].extend(values_to_add)
278
+ upper_name = value["name"].upper()
279
+ if upper_name[0] in "0123456789":
280
+ upper_name = "ENUM_" + upper_name
281
+ value["name"] = upper_name
294
282
 
295
283
  # add type for reference
296
284
  for v in HEADERS_CONVERT_IN_METHOD.values():
@@ -56,7 +56,6 @@ class PadType(str, Enum):
56
56
  ENUM_CLASS = "Enum"
57
57
  METHOD = "_method"
58
58
  PARAMETER = "_parameter"
59
- ENUM_VALUE = "_enum"
60
59
  PROPERTY = "_property"
61
60
  OPERATION_GROUP = "Operations"
62
61
 
@@ -183,7 +182,6 @@ RESERVED_WORDS = {
183
182
  PadType.MODEL: ["enum", *_always_reserved],
184
183
  PadType.PROPERTY: ["self", *_always_reserved],
185
184
  PadType.ENUM_CLASS: ["enum", *_always_reserved],
186
- PadType.ENUM_VALUE: ["mro", *_always_reserved],
187
185
  PadType.OPERATION_GROUP: [*_always_reserved],
188
186
  }
189
187
 
@@ -4,11 +4,11 @@
4
4
  "install": [
5
5
  {
6
6
  "download_info": {
7
- "url": "https://files.pythonhosted.org/packages/e1/c6/76dc613121b793286a3f91621d7b75a2b493e0390ddca50f11993eadf192/setuptools-82.0.0-py3-none-any.whl",
7
+ "url": "https://files.pythonhosted.org/packages/9d/76/f789f7a86709c6b087c5a2f52f911838cad707cc613162401badc665acfe/setuptools-82.0.1-py3-none-any.whl",
8
8
  "archive_info": {
9
- "hash": "sha256=70b18734b607bd1da571d097d236cfcfacaf01de45717d59e6e04b96877532e0",
9
+ "hash": "sha256=a59e362652f08dcd477c78bb6e7bd9d80a7995bc73ce773050228a348ce2e5bb",
10
10
  "hashes": {
11
- "sha256": "70b18734b607bd1da571d097d236cfcfacaf01de45717d59e6e04b96877532e0"
11
+ "sha256": "a59e362652f08dcd477c78bb6e7bd9d80a7995bc73ce773050228a348ce2e5bb"
12
12
  }
13
13
  }
14
14
  },
@@ -18,11 +18,11 @@
18
18
  "metadata": {
19
19
  "metadata_version": "2.4",
20
20
  "name": "setuptools",
21
- "version": "82.0.0",
21
+ "version": "82.0.1",
22
22
  "dynamic": [
23
23
  "license-file"
24
24
  ],
25
- "summary": "Easily download, build, install, upgrade, and uninstall Python packages",
25
+ "summary": "Most extensible Python build backend with support for C/C++ extension modules",
26
26
  "description": ".. |pypi-version| image:: https://img.shields.io/pypi/v/setuptools.svg\n :target: https://pypi.org/project/setuptools\n\n.. |py-version| image:: https://img.shields.io/pypi/pyversions/setuptools.svg\n\n.. |test-badge| image:: https://github.com/pypa/setuptools/actions/workflows/main.yml/badge.svg\n :target: https://github.com/pypa/setuptools/actions?query=workflow%3A%22tests%22\n :alt: tests\n\n.. |ruff-badge| image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json\n :target: https://github.com/astral-sh/ruff\n :alt: Ruff\n\n.. |docs-badge| image:: https://img.shields.io/readthedocs/setuptools/latest.svg\n :target: https://setuptools.pypa.io\n\n.. |skeleton-badge| image:: https://img.shields.io/badge/skeleton-2025-informational\n :target: https://blog.jaraco.com/skeleton\n\n.. |codecov-badge| image:: https://img.shields.io/codecov/c/github/pypa/setuptools/master.svg?logo=codecov&logoColor=white\n :target: https://codecov.io/gh/pypa/setuptools\n\n.. |tidelift-badge| image:: https://tidelift.com/badges/github/pypa/setuptools?style=flat\n :target: https://tidelift.com/subscription/pkg/pypi-setuptools?utm_source=pypi-setuptools&utm_medium=readme\n\n.. |discord-badge| image:: https://img.shields.io/discord/803025117553754132\n :target: https://discord.com/channels/803025117553754132/815945031150993468\n :alt: Discord\n\n|pypi-version| |py-version| |test-badge| |ruff-badge| |docs-badge| |skeleton-badge| |codecov-badge| |discord-badge|\n\nSee the `Quickstart <https://setuptools.pypa.io/en/latest/userguide/quickstart.html>`_\nand the `User's Guide <https://setuptools.pypa.io/en/latest/userguide/>`_ for\ninstructions on how to use Setuptools.\n\nQuestions and comments should be directed to `GitHub Discussions\n<https://github.com/pypa/setuptools/discussions>`_.\nBug reports and especially tested patches may be\nsubmitted directly to the `bug tracker\n<https://github.com/pypa/setuptools/issues>`_.\n\n\nCode of Conduct\n===============\n\nEveryone interacting in the setuptools project's codebases, issue trackers,\nchat rooms, and fora is expected to follow the\n`PSF Code of Conduct <https://github.com/pypa/.github/blob/main/CODE_OF_CONDUCT.md>`_.\n\n\nFor Enterprise\n==============\n\nAvailable as part of the Tidelift Subscription.\n\nSetuptools and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.\n\n`Learn more <https://tidelift.com/subscription/pkg/pypi-setuptools?utm_source=pypi-setuptools&utm_medium=referral&utm_campaign=github>`_.\n",
27
27
  "description_content_type": "text/x-rst",
28
28
  "keywords": [
@@ -88,7 +88,6 @@
88
88
  "importlib_metadata>=6; python_version < \"3.10\" and extra == \"core\"",
89
89
  "tomli>=2.0.1; python_version < \"3.11\" and extra == \"core\"",
90
90
  "wheel>=0.43.0; extra == \"core\"",
91
- "platformdirs>=4.2.2; extra == \"core\"",
92
91
  "jaraco.functools>=4; extra == \"core\"",
93
92
  "more_itertools; extra == \"core\"",
94
93
  "pytest-checkdocs>=2.4; extra == \"check\"",
@@ -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
 
@@ -296,11 +296,11 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
296
296
 
297
297
  serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
298
298
  file_import = FileImport(self.code_model)
299
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
299
+ file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.REGULAR)
300
300
 
301
301
  response_types = [r.type_annotation(async_mode=async_mode, **kwargs) for r in self.responses if r.type]
302
302
  if len(set(response_types)) > 1:
303
- file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL)
303
+ file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.REGULAR)
304
304
  if self.added_on:
305
305
  serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
306
306
  file_import.add_submodule_import(
@@ -406,9 +406,9 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
406
406
  ImportType.SDKCORE,
407
407
  )
408
408
  file_import.add_submodule_import("rest", "HttpRequest", ImportType.SDKCORE)
409
- file_import.add_submodule_import("typing", "Callable", ImportType.STDLIB, TypingSection.CONDITIONAL)
410
- file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL)
411
- 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)
412
412
  if self.code_model.options["tracing"] and self.want_tracing and not async_mode:
413
413
  file_import.add_submodule_import(
414
414
  "azure.core.tracing.decorator",
@@ -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"))
@@ -150,11 +150,11 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
150
150
  f"{self.code_model.core_library}.{default_paging_submodule}",
151
151
  "AsyncItemPaged",
152
152
  ImportType.SDKCORE,
153
- TypingSection.CONDITIONAL,
153
+ TypingSection.REGULAR,
154
154
  )
155
155
  else:
156
156
  file_import.add_submodule_import(
157
- 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
158
158
  )
159
159
  if (
160
160
  self.next_request_builder
@@ -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:
@@ -650,6 +652,9 @@ class Model(_MyMutableMapping):
650
652
  if len(items) > 0:
651
653
  existed_attr_keys.append(xml_name)
652
654
  dict_to_pass[rf._rest_name] = _deserialize(rf._type, items)
655
+ elif not rf._is_optional:
656
+ existed_attr_keys.append(xml_name)
657
+ dict_to_pass[rf._rest_name] = []
653
658
  continue
654
659
 
655
660
  # text element is primitive type
@@ -928,6 +933,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur
928
933
  # is it optional?
929
934
  try:
930
935
  if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore
936
+ if rf:
937
+ rf._is_optional = True
931
938
  if len(annotation.__args__) <= 2: # pyright: ignore
932
939
  if_obj_deserializer = _get_deserialize_callable_from_annotation(
933
940
  next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore
@@ -1020,16 +1027,20 @@ def _deserialize_with_callable(
1020
1027
  return float(value.text) if value.text else None
1021
1028
  if deserializer is bool:
1022
1029
  return value.text == "true" if value.text else None
1030
+ if deserializer and deserializer in _DESERIALIZE_MAPPING.values():
1031
+ return deserializer(value.text) if value.text else None
1032
+ if deserializer and deserializer in _DESERIALIZE_MAPPING_WITHFORMAT.values():
1033
+ return deserializer(value.text) if value.text else None
1023
1034
  if deserializer is None:
1024
1035
  return value
1025
1036
  if deserializer in [int, float, bool]:
1026
1037
  return deserializer(value)
1027
1038
  if isinstance(deserializer, CaseInsensitiveEnumMeta):
1028
1039
  try:
1029
- return deserializer(value)
1040
+ return deserializer(value.text if isinstance(value, ET.Element) else value)
1030
1041
  except ValueError:
1031
1042
  # for unknown value, return raw value
1032
- return value
1043
+ return value.text if isinstance(value, ET.Element) else value
1033
1044
  if isinstance(deserializer, type) and issubclass(deserializer, Model):
1034
1045
  return deserializer._deserialize(value, [])
1035
1046
  return typing.cast(typing.Callable[[typing.Any], typing.Any], deserializer)(value)
@@ -1084,9 +1095,7 @@ def _failsafe_deserialize_xml(
1084
1095
  return None
1085
1096
 
1086
1097
 
1087
- {% if code_model.has_padded_model_property %}
1088
1098
  # pylint: disable=too-many-instance-attributes
1089
- {% endif %}
1090
1099
  class _RestField:
1091
1100
  def __init__(
1092
1101
  self,
@@ -1109,6 +1118,7 @@ class _RestField:
1109
1118
  self._is_discriminator = is_discriminator
1110
1119
  self._visibility = visibility
1111
1120
  self._is_model = False
1121
+ self._is_optional = False
1112
1122
  self._default = default
1113
1123
  self._format = format
1114
1124
  self._is_multipart_file_input = is_multipart_file_input
@@ -4,6 +4,7 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  """The preprocessing autorest plugin."""
7
+
7
8
  import copy
8
9
  from typing import Callable, Any, Optional
9
10
 
@@ -21,7 +22,6 @@ from ..utils import (
21
22
  get_body_type_for_description,
22
23
  JSON_REGEXP,
23
24
  KNOWN_TYPES,
24
- update_enum_value,
25
25
  )
26
26
 
27
27
 
@@ -267,30 +267,18 @@ class PreProcessPlugin(YamlUpdatePlugin):
267
267
  add_redefined_builtin_info(property["clientName"], property)
268
268
  if type.get("name"):
269
269
  pad_type = PadType.MODEL if type["type"] == "model" else PadType.ENUM_CLASS
270
- name = self.pad_reserved_words(type["name"], pad_type, type)
271
- type["name"] = name[0].upper() + name[1:]
270
+ if type["type"] != "enumvalue":
271
+ name = self.pad_reserved_words(type["name"], pad_type, type)
272
+ type["name"] = name[0].upper() + name[1:]
272
273
  type["description"] = update_description(type.get("description", ""), type["name"])
273
274
  type["snakeCaseName"] = to_snake_case(type["name"])
274
275
  if type.get("values"):
275
- # we're enums
276
- values_to_add = []
276
+ # we're enums - enum values are UPPER_CASE so no padding needed for reserved words
277
277
  for value in type["values"]:
278
- padded_name = self.pad_reserved_words(value["name"].lower(), PadType.ENUM_VALUE, value).upper()
279
- if self.version_tolerant:
280
- if padded_name[0] in "0123456789":
281
- padded_name = "ENUM_" + padded_name
282
- value["name"] = padded_name
283
- else:
284
- if value["name"] != padded_name:
285
- values_to_add.append(
286
- update_enum_value(
287
- name=padded_name,
288
- value=value["value"],
289
- description=value["description"],
290
- enum_type=value["enumType"],
291
- )
292
- )
293
- type["values"].extend(values_to_add)
278
+ upper_name = value["name"].upper()
279
+ if upper_name[0] in "0123456789":
280
+ upper_name = "ENUM_" + upper_name
281
+ value["name"] = upper_name
294
282
 
295
283
  # add type for reference
296
284
  for v in HEADERS_CONVERT_IN_METHOD.values():
@@ -56,7 +56,6 @@ class PadType(str, Enum):
56
56
  ENUM_CLASS = "Enum"
57
57
  METHOD = "_method"
58
58
  PARAMETER = "_parameter"
59
- ENUM_VALUE = "_enum"
60
59
  PROPERTY = "_property"
61
60
  OPERATION_GROUP = "Operations"
62
61
 
@@ -183,7 +182,6 @@ RESERVED_WORDS = {
183
182
  PadType.MODEL: ["enum", *_always_reserved],
184
183
  PadType.PROPERTY: ["self", *_always_reserved],
185
184
  PadType.ENUM_CLASS: ["enum", *_always_reserved],
186
- PadType.ENUM_VALUE: ["mro", *_always_reserved],
187
185
  PadType.OPERATION_GROUP: [*_always_reserved],
188
186
  }
189
187
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.49.1",
3
+ "version": "6.50.0",
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.1",
22
+ "@typespec/http-client-python": "~0.28.0",
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",