@autorest/python 6.9.2 → 6.9.3

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.
@@ -8,6 +8,19 @@ import re
8
8
  import argparse
9
9
 
10
10
 
11
+ def update_enum_value(
12
+ name: str, value: Any, description: str, enum_type: Dict[str, Any]
13
+ ) -> Dict[str, Any]:
14
+ return {
15
+ "name": name,
16
+ "type": "enumvalue",
17
+ "value": value,
18
+ "description": description,
19
+ "enumType": enum_type,
20
+ "valueType": enum_type["valueType"],
21
+ }
22
+
23
+
11
24
  def to_snake_case(name: str) -> str:
12
25
  def replace_upper_characters(m) -> str:
13
26
  match_str = m.group().lower()
@@ -4,7 +4,7 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  import logging
7
- from typing import Any, Dict, Union
7
+ from typing import Any, Dict, Union, Optional
8
8
  from .base import BaseModel
9
9
  from .base_builder import BaseBuilder, ParameterListType
10
10
  from .code_model import CodeModel
@@ -30,7 +30,7 @@ from .primitive_types import (
30
30
  UnixTimeType,
31
31
  AzureCoreType,
32
32
  )
33
- from .enum_type import EnumType
33
+ from .enum_type import EnumType, EnumValue
34
34
  from .base import BaseType
35
35
  from .constant_type import ConstantType
36
36
  from .imports import FileImport, ImportType, TypingSection
@@ -86,6 +86,7 @@ __all__ = [
86
86
  "DictionaryType",
87
87
  "ListType",
88
88
  "EnumType",
89
+ "EnumValue",
89
90
  "FileImport",
90
91
  "ImportType",
91
92
  "TypingSection",
@@ -128,6 +129,7 @@ TYPE_TO_OBJECT = {
128
129
  "dict": DictionaryType,
129
130
  "constant": ConstantType,
130
131
  "enum": EnumType,
132
+ "enumvalue": EnumValue,
131
133
  "binary": BinaryType,
132
134
  "any": AnyType,
133
135
  "datetime": DatetimeType,
@@ -157,6 +159,7 @@ def build_type(yaml_data: Dict[str, Any], code_model: CodeModel) -> BaseType:
157
159
  except KeyError:
158
160
  # Not created yet, let's create it and add it to the index
159
161
  pass
162
+ response: Optional[BaseType] = None
160
163
  if yaml_data["type"] == "model":
161
164
  # need to special case model to avoid recursion
162
165
  if yaml_data["base"] == "json" or not code_model.options["models_mode"]:
@@ -168,6 +171,16 @@ def build_type(yaml_data: Dict[str, Any], code_model: CodeModel) -> BaseType:
168
171
  response = model_type(yaml_data, code_model)
169
172
  code_model.types_map[yaml_id] = response
170
173
  response.fill_instance_from_yaml(yaml_data, code_model)
174
+ elif yaml_data["type"] == "enum":
175
+ # avoid recursion because we add the parent enum type to the enum value
176
+ response = EnumType(
177
+ yaml_data,
178
+ code_model,
179
+ values=[],
180
+ value_type=build_type(yaml_data["valueType"], code_model),
181
+ )
182
+ code_model.types_map[yaml_id] = response
183
+ response.fill_instance_from_yaml(yaml_data, code_model)
171
184
  else:
172
185
  object_type = yaml_data.get("type")
173
186
  if object_type not in TYPE_TO_OBJECT:
@@ -177,6 +190,8 @@ def build_type(yaml_data: Dict[str, Any], code_model: CodeModel) -> BaseType:
177
190
  )
178
191
  object_type = "string"
179
192
  response = TYPE_TO_OBJECT[object_type].from_yaml(yaml_data, code_model) # type: ignore
193
+ if response is None:
194
+ raise ValueError("response can not be None")
180
195
  code_model.types_map[yaml_id] = response
181
196
  return response
182
197
 
@@ -6,7 +6,7 @@
6
6
  import logging
7
7
  from typing import Dict, Any, Optional, TYPE_CHECKING
8
8
  from .base import BaseType
9
- from .imports import FileImport, ImportType, TypingSection
9
+ from .imports import FileImport
10
10
  from .primitive_types import IntegerType, BinaryType, StringType, BooleanType
11
11
  from .utils import add_to_description
12
12
 
@@ -134,21 +134,7 @@ class ConstantType(BaseType):
134
134
  def imports(self, **kwargs: Any) -> FileImport:
135
135
  file_import = self._imports_shared(**kwargs)
136
136
  if self._is_literal:
137
- file_import.add_import("sys", ImportType.STDLIB)
138
- file_import.add_submodule_import(
139
- "typing_extensions",
140
- "Literal",
141
- ImportType.BYVERSION,
142
- TypingSection.REGULAR,
143
- None,
144
- (
145
- (
146
- (3, 8),
147
- "typing",
148
- "pylint: disable=no-name-in-module, ungrouped-imports",
149
- ),
150
- ),
151
- )
137
+ file_import.add_literal_import()
152
138
  return file_import
153
139
 
154
140
  @property
@@ -3,17 +3,16 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- from typing import Any, Dict, List, TYPE_CHECKING, Optional
6
+ from typing import Any, Dict, List, TYPE_CHECKING, Optional, cast
7
7
 
8
8
  from .base import BaseType
9
9
  from .imports import FileImport, ImportType, TypingSection
10
- from .base import BaseModel
11
10
 
12
11
  if TYPE_CHECKING:
13
12
  from .code_model import CodeModel
14
13
 
15
14
 
16
- class EnumValue(BaseModel):
15
+ class EnumValue(BaseType):
17
16
  """Model containing necessary information for a single value of an enum.
18
17
 
19
18
  :param str name: The name of this enum value
@@ -21,11 +20,70 @@ class EnumValue(BaseModel):
21
20
  :param str description: Optional. The description for this enum value
22
21
  """
23
22
 
24
- def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
23
+ def __init__(
24
+ self,
25
+ yaml_data: Dict[str, Any],
26
+ code_model: "CodeModel",
27
+ enum_type: "EnumType",
28
+ value_type: BaseType,
29
+ ) -> None:
25
30
  super().__init__(yaml_data=yaml_data, code_model=code_model)
26
31
  self.name: str = self.yaml_data["name"]
27
32
  self.value: str = self.yaml_data["value"]
28
- self.description: Optional[str] = self.yaml_data.get("description")
33
+ self.enum_type = enum_type
34
+ self.value_type = value_type
35
+
36
+ def description(self, *, is_operation_file: bool) -> str:
37
+ return self.yaml_data.get("description", "")
38
+
39
+ def type_annotation(self, **kwargs: Any) -> str:
40
+ """The python type used for type annotation"""
41
+ return f"Literal[{self.enum_type.name}.{self.name}]"
42
+
43
+ def get_declaration(self, value=None):
44
+ return self.enum_type.name + "." + self.name
45
+
46
+ def docstring_text(self, **kwargs: Any) -> str:
47
+ return self.enum_type.name + "." + self.name
48
+
49
+ def docstring_type(self, **kwargs: Any) -> str:
50
+ """The python type used for RST syntax input and type annotation."""
51
+
52
+ type_annotation = self.value_type.type_annotation(**kwargs)
53
+ enum_type_annotation = f"{self.code_model.namespace}.models.{self.name}"
54
+ return f"{type_annotation} or ~{enum_type_annotation}"
55
+
56
+ def get_json_template_representation(
57
+ self,
58
+ *,
59
+ optional: bool = True,
60
+ client_default_value_declaration: Optional[str] = None,
61
+ description: Optional[str] = None,
62
+ ) -> Any:
63
+ # for better display effect, use the only value instead of var type
64
+ return self.value_type.get_json_template_representation(
65
+ optional=optional,
66
+ client_default_value_declaration=client_default_value_declaration,
67
+ description=description,
68
+ )
69
+
70
+ @property
71
+ def serialization_type(self) -> str:
72
+ return self.value_type.serialization_type
73
+
74
+ @property
75
+ def instance_check_template(self) -> str:
76
+ return self.value_type.instance_check_template
77
+
78
+ def imports(self, **kwargs: Any) -> FileImport:
79
+ file_import = FileImport()
80
+ file_import.merge(self.value_type.imports(**kwargs))
81
+ file_import.add_literal_import()
82
+ file_import.add_submodule_import(
83
+ "._enums", self.enum_type.name, ImportType.LOCAL, TypingSection.REGULAR
84
+ )
85
+
86
+ return file_import
29
87
 
30
88
  @classmethod
31
89
  def from_yaml(
@@ -39,9 +97,14 @@ class EnumValue(BaseModel):
39
97
  :return: A created EnumValue
40
98
  :rtype: ~autorest.models.EnumValue
41
99
  """
100
+ from . import build_type
101
+
102
+ enum_type = cast(EnumType, code_model.lookup_type(id(yaml_data["enumType"])))
42
103
  return cls(
43
104
  yaml_data=yaml_data,
44
105
  code_model=code_model,
106
+ enum_type=enum_type,
107
+ value_type=build_type(yaml_data["valueType"], code_model),
45
108
  )
46
109
 
47
110
 
@@ -150,27 +213,19 @@ class EnumType(BaseType):
150
213
  def instance_check_template(self) -> str:
151
214
  return self.value_type.instance_check_template
152
215
 
216
+ def fill_instance_from_yaml(
217
+ self, yaml_data: Dict[str, Any], code_model: "CodeModel"
218
+ ) -> None:
219
+ for value in yaml_data["values"]:
220
+ self.values.append(EnumValue.from_yaml(value, code_model))
221
+
153
222
  @classmethod
154
223
  def from_yaml(
155
224
  cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
156
225
  ) -> "EnumType":
157
- """Constructs an EnumType from yaml data.
158
-
159
- :param yaml_data: the yaml data from which we will construct this schema
160
- :type yaml_data: dict[str, Any]
161
-
162
- :return: A created EnumType
163
- :rtype: ~autorest.models.EnumType
164
- """
165
- from . import build_type
166
-
167
- return cls(
168
- yaml_data=yaml_data,
169
- code_model=code_model,
170
- value_type=build_type(yaml_data["valueType"], code_model),
171
- values=[
172
- EnumValue.from_yaml(value, code_model) for value in yaml_data["values"]
173
- ],
226
+ raise ValueError(
227
+ "You shouldn't call from_yaml for EnumType to avoid recursion. "
228
+ "Please initial a blank EnumType, then call .fill_instance_from_yaml on the created type."
174
229
  )
175
230
 
176
231
  def imports(self, **kwargs: Any) -> FileImport:
@@ -183,6 +183,23 @@ class FileImport:
183
183
  )
184
184
  self.add_submodule_import("typing", "Any", ImportType.STDLIB)
185
185
 
186
+ def add_literal_import(self) -> None:
187
+ self.add_import("sys", ImportType.STDLIB)
188
+ self.add_submodule_import(
189
+ "typing_extensions",
190
+ "Literal",
191
+ ImportType.BYVERSION,
192
+ TypingSection.REGULAR,
193
+ None,
194
+ (
195
+ (
196
+ (3, 8),
197
+ "typing",
198
+ "pylint: disable=no-name-in-module, ungrouped-imports",
199
+ ),
200
+ ),
201
+ )
202
+
186
203
  def to_dict(
187
204
  self,
188
205
  ) -> Dict[
@@ -92,6 +92,9 @@ class _ParameterBase(
92
92
  )
93
93
  self.hide_in_method: bool = self.yaml_data.get("hideInMethod", False)
94
94
 
95
+ def get_declaration(self, value: Any = None) -> Any:
96
+ return self.type.get_declaration(value)
97
+
95
98
  @property
96
99
  def hide_in_operation_signature(self) -> bool:
97
100
  return False
@@ -115,7 +118,7 @@ class _ParameterBase(
115
118
  if self.optional and isinstance(self.type, ConstantType):
116
119
  base_description = add_to_description(
117
120
  base_description,
118
- f"Known values are {self.type.get_declaration()} and None.",
121
+ f"Known values are {self.get_declaration()} and None.",
119
122
  )
120
123
  if not (self.optional or self.client_default_value):
121
124
  base_description = add_to_description(base_description, "Required.")
@@ -141,7 +144,7 @@ class _ParameterBase(
141
144
  """Declaration of parameter's client default value"""
142
145
  if self.client_default_value is None:
143
146
  return None
144
- return self.type.get_declaration(self.client_default_value)
147
+ return self.get_declaration(self.client_default_value)
145
148
 
146
149
  def type_annotation(self, **kwargs: Any) -> str:
147
150
  kwargs["is_operation_file"] = True
@@ -7,6 +7,7 @@ from typing import Any, Dict, Optional, TYPE_CHECKING, List
7
7
 
8
8
  from .base import BaseModel
9
9
  from .constant_type import ConstantType
10
+ from .enum_type import EnumType
10
11
  from .base import BaseType
11
12
  from .imports import FileImport, ImportType
12
13
  from .utils import add_to_description, add_to_pylint_disable
@@ -61,9 +62,9 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
61
62
  @property
62
63
  def client_default_value_declaration(self) -> str:
63
64
  if self.client_default_value is not None:
64
- return self.type.get_declaration(self.client_default_value)
65
+ return self.get_declaration(self.client_default_value)
65
66
  if self.type.client_default_value is not None:
66
- return self.type.get_declaration(self.type.client_default_value)
67
+ return self.get_declaration(self.type.client_default_value)
67
68
  return "None"
68
69
 
69
70
  @property
@@ -88,11 +89,24 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
88
89
  def msrest_deserialization_key(self) -> str:
89
90
  return self.type.msrest_deserialization_key
90
91
 
92
+ @property
93
+ def is_enum_discriminator(self) -> bool:
94
+ return self.is_discriminator and self.type.type == "enum"
95
+
91
96
  def type_annotation(self, *, is_operation_file: bool = False) -> str:
97
+ if self.is_enum_discriminator:
98
+ # here we are the enum discriminator property on the base model
99
+ return "Literal[None]"
92
100
  if self.optional and self.client_default_value is None:
93
101
  return f"Optional[{self.type.type_annotation(is_operation_file=is_operation_file)}]"
94
102
  return self.type.type_annotation(is_operation_file=is_operation_file)
95
103
 
104
+ def get_declaration(self, value: Any = None) -> Any:
105
+ if self.is_enum_discriminator:
106
+ # here we are the enum discriminator property on the base model
107
+ return None
108
+ return self.type.get_declaration(value)
109
+
96
110
  def get_json_template_representation(
97
111
  self,
98
112
  *,
@@ -101,7 +115,7 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
101
115
  description: Optional[str] = None,
102
116
  ) -> Any:
103
117
  if self.client_default_value:
104
- client_default_value_declaration = self.type.get_declaration(
118
+ client_default_value_declaration = self.get_declaration(
105
119
  self.client_default_value
106
120
  )
107
121
  if self.description(is_operation_file=True):
@@ -131,7 +145,12 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
131
145
  return retval or None
132
146
 
133
147
  def imports(self, **kwargs) -> FileImport:
134
- file_import = self.type.imports(**kwargs, relative_path="..", model_typing=True)
148
+ file_import = FileImport()
149
+ if self.is_discriminator and isinstance(self.type, EnumType):
150
+ return file_import
151
+ file_import.merge(
152
+ self.type.imports(**kwargs, relative_path="..", model_typing=True)
153
+ )
135
154
  if self.optional and self.client_default_value is None:
136
155
  file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
137
156
  if self.code_model.options["models_mode"] == "dpg":
@@ -26,7 +26,6 @@ from ..models import (
26
26
  ParameterMethodLocation,
27
27
  RequestBuilderBodyParameter,
28
28
  OverloadedRequestBuilder,
29
- ConstantType,
30
29
  MultipartBodyParameter,
31
30
  Property,
32
31
  RequestBuilderType,
@@ -458,15 +457,16 @@ class RequestBuilderSerializer(
458
457
  @staticmethod
459
458
  def declare_non_inputtable_constants(builder: RequestBuilderType) -> List[str]:
460
459
  def _get_value(param):
461
- param_type = cast(ConstantType, param.type)
462
460
  if param.location in [ParameterLocation.HEADER, ParameterLocation.QUERY]:
463
461
  kwarg_dict = (
464
462
  "headers"
465
463
  if param.location == ParameterLocation.HEADER
466
464
  else "params"
467
465
  )
468
- return f"_{kwarg_dict}.pop('{param.wire_name}', {param_type.get_declaration()})"
469
- return f"{param_type.get_declaration()}"
466
+ return (
467
+ f"_{kwarg_dict}.pop('{param.wire_name}', {param.get_declaration()})"
468
+ )
469
+ return f"{param.get_declaration()}"
470
470
 
471
471
  return [
472
472
  f"{p.client_name} = {_get_value(p)}"
@@ -645,7 +645,7 @@ class _OperationSerializer(
645
645
  f"_stream = {stream_value}",
646
646
  f"pipeline_response: PipelineResponse = {self._call_method}self._client._pipeline.run( "
647
647
  + f"{'# type: ignore' if type_ignore else ''} # pylint: disable=protected-access",
648
- " request,",
648
+ " _request,",
649
649
  " stream=_stream,",
650
650
  " **kwargs",
651
651
  ")",
@@ -915,7 +915,7 @@ class _OperationSerializer(
915
915
  ("_" + group_name) if group_name else "",
916
916
  request_builder.name,
917
917
  )
918
- retval.append(f"request = {request_path_name}(")
918
+ retval.append(f"_request = {request_path_name}(")
919
919
  for parameter in request_builder.parameters.method:
920
920
  if parameter.location == ParameterLocation.BODY:
921
921
  # going to pass in body later based off of overloads
@@ -979,14 +979,14 @@ class _OperationSerializer(
979
979
  and builder.parameters.body_parameter.client_name == "files"
980
980
  ):
981
981
  pass_files = ", _files"
982
- retval.append(f"request = _convert_request(request{pass_files})")
982
+ retval.append(f"_request = _convert_request(_request{pass_files})")
983
983
  if builder.parameters.path:
984
984
  retval.extend(self.serialize_path(builder))
985
- url_to_format = "request.url"
985
+ url_to_format = "_request.url"
986
986
  if self.code_model.options["version_tolerant"] and template_url:
987
987
  url_to_format = template_url
988
988
  retval.append(
989
- "request.url = self._client.format_url({}{})".format(
989
+ "_request.url = self._client.format_url({}{})".format(
990
990
  url_to_format,
991
991
  ", **path_format_arguments" if builder.parameters.path else "",
992
992
  )
@@ -1168,31 +1168,16 @@ class _OperationSerializer(
1168
1168
  )
1169
1169
  )
1170
1170
  retval.append("")
1171
- type_ignore = (
1172
- builder.has_response_body
1173
- and not builder.has_optional_return_type
1174
- and not (
1175
- self.code_model.options["models_mode"] == "msrest"
1176
- and any(not resp.is_stream_response for resp in builder.responses)
1177
- )
1178
- )
1179
1171
  if builder.has_optional_return_type or self.code_model.options["models_mode"]:
1180
1172
  deserialized = "deserialized"
1181
1173
  else:
1182
1174
  deserialized = f"cast({builder.response_type_annotation(async_mode=self.async_mode)}, deserialized)"
1183
- type_ignore = False
1184
- if (
1185
- not builder.has_optional_return_type
1186
- and len(builder.responses) > 1
1187
- and any(resp.is_stream_response or resp.type for resp in builder.responses)
1188
- ):
1189
- type_ignore = True
1190
1175
  retval.append("if cls:")
1191
1176
  retval.append(
1192
1177
  " return cls(pipeline_response, {}, {}){}".format(
1193
1178
  deserialized if builder.has_response_body else "None",
1194
1179
  "response_headers" if builder.any_response_has_headers else "{}",
1195
- " # type: ignore" if type_ignore else "",
1180
+ " # type: ignore",
1196
1181
  )
1197
1182
  )
1198
1183
  if builder.has_response_body and any(
@@ -1200,9 +1185,7 @@ class _OperationSerializer(
1200
1185
  for response in builder.responses
1201
1186
  ):
1202
1187
  retval.append("")
1203
- retval.append(
1204
- f"return {deserialized}{' # type: ignore' if type_ignore else ''}"
1205
- )
1188
+ retval.append(f"return {deserialized} # type: ignore")
1206
1189
  if (
1207
1190
  builder.request_builder.method == "HEAD"
1208
1191
  and self.code_model.options["head_as_boolean"]
@@ -1370,8 +1353,8 @@ class _PagingOperationSerializer(
1370
1353
  except StopIteration:
1371
1354
  pass
1372
1355
 
1373
- retval.append(f'request = HttpRequest("GET", {next_link_str}{query_str})')
1374
- retval.extend(self._postprocess_http_request(builder, "request.url"))
1356
+ retval.append(f'_request = HttpRequest("GET", {next_link_str}{query_str})')
1357
+ retval.extend(self._postprocess_http_request(builder, "_request.url"))
1375
1358
 
1376
1359
  return retval
1377
1360
 
@@ -1391,10 +1374,10 @@ class _PagingOperationSerializer(
1391
1374
  [f" {line}" for line in self.call_next_link_request_builder(builder)]
1392
1375
  )
1393
1376
  if not builder.next_request_builder and self.code_model.is_legacy:
1394
- retval.append(' request.method = "GET"')
1377
+ retval.append(' _request.method = "GET"')
1395
1378
  else:
1396
1379
  retval.append("")
1397
- retval.append(" return request")
1380
+ retval.append(" return _request")
1398
1381
  return retval
1399
1382
 
1400
1383
  @property
@@ -1453,7 +1436,7 @@ class _PagingOperationSerializer(
1453
1436
 
1454
1437
  def _get_next_callback(self, builder: PagingOperationType) -> List[str]:
1455
1438
  retval = [f"{'async ' if self.async_mode else ''}def get_next(next_link=None):"]
1456
- retval.append(" request = prepare_request(next_link)")
1439
+ retval.append(" _request = prepare_request(next_link)")
1457
1440
  retval.append("")
1458
1441
  retval.extend([f" {l}" for l in self.make_pipeline_call(builder)])
1459
1442
  retval.append(" response = pipeline_response.http_response")
@@ -1626,11 +1609,7 @@ class _LROOperationSerializer(_OperationSerializer[LROOperationType]):
1626
1609
  "response_headers"
1627
1610
  if builder.lro_response and builder.lro_response.headers
1628
1611
  else "{}",
1629
- " # type: ignore"
1630
- if builder.lro_response
1631
- and builder.lro_response.type
1632
- and self.code_model.options["models_mode"] != "msrest"
1633
- else "",
1612
+ " # type: ignore",
1634
1613
  )
1635
1614
  )
1636
1615
  if builder.lro_response and builder.lro_response.type:
@@ -3,14 +3,13 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- from typing import List, cast
6
+ from typing import List
7
7
  from abc import ABC, abstractmethod
8
8
 
9
9
  from jinja2 import Environment
10
- from ..models import ModelType, CodeModel, Property
10
+ from ..models import ModelType, CodeModel, Property, ConstantType, EnumValue
11
11
  from ..models.imports import FileImport, TypingSection, MsrestImportType, ImportType
12
12
  from .import_serializer import FileImportSerializer
13
- from ..models.constant_type import ConstantType
14
13
 
15
14
 
16
15
  def _documentation_string(
@@ -266,8 +265,8 @@ class DpgModelSerializer(_ModelSerializer):
266
265
  field = "rest_discriminator" if prop.is_discriminator else "rest_field"
267
266
  type_ignore = (
268
267
  prop.is_discriminator
269
- and prop.is_discriminator
270
- and cast(ConstantType, prop.type).value
268
+ and isinstance(prop.type, (ConstantType, EnumValue))
269
+ and prop.type.value
271
270
  )
272
271
  return (
273
272
  f"{prop.client_name}: {prop.type_annotation()} ="
@@ -280,7 +279,7 @@ class DpgModelSerializer(_ModelSerializer):
280
279
  if prop.constant or prop.is_discriminator:
281
280
  init_args.append(
282
281
  f"self.{prop.client_name}: {prop.type_annotation()} = "
283
- f"{cast(ConstantType, prop.type).get_declaration()}"
282
+ f"{prop.get_declaration()}"
284
283
  )
285
284
  return init_args
286
285
 
@@ -24,7 +24,7 @@
24
24
  {% else %}
25
25
  request_copy.url = self._client.format_url(request_copy.url)
26
26
  {% endif %}
27
- return self._client.send_request(request_copy, **kwargs)
27
+ return self._client.send_request(request_copy, **kwargs) # type: ignore
28
28
 
29
29
  {{ keywords.def }} close(self) -> None:
30
30
  {{ keywords.await }}self._client.close()
@@ -7,7 +7,7 @@ class {{ enum.name }}({{ enum.value_type.type_annotation(is_operation_file=False
7
7
 
8
8
  {% for value in enum.values %}
9
9
  {{ value.name }} = {{ enum.value_type.get_declaration(value.value) }}
10
- {% if value.description %}
11
- """{{ value.description | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n #: ') }}"""
10
+ {% if value.description(is_operation_file=False) %}
11
+ """{{ value.description(is_operation_file=False) | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n #: ') }}"""
12
12
  {% endif %}
13
- {% endfor %}
13
+ {% endfor %}
@@ -295,7 +295,7 @@ class Model(object):
295
295
  _validation: Dict[str, Dict[str, Any]] = {}
296
296
 
297
297
  def __init__(self, **kwargs: Any) -> None:
298
- self.additional_properties: Dict[str, Any] = {}
298
+ self.additional_properties: Optional[Dict[str, Any]] = {}
299
299
  for k in kwargs:
300
300
  if k not in self._attribute_map:
301
301
  _LOGGER.warning("%s is not a known attribute of class %s and will be ignored", k, self.__class__)
@@ -351,7 +351,7 @@ class Model(object):
351
351
  :rtype: dict
352
352
  """
353
353
  serializer = Serializer(self._infer_class_models())
354
- return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs)
354
+ return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs) # type: ignore
355
355
 
356
356
  def as_dict(
357
357
  self,
@@ -392,7 +392,7 @@ class Model(object):
392
392
  :rtype: dict
393
393
  """
394
394
  serializer = Serializer(self._infer_class_models())
395
- return serializer._serialize(self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs)
395
+ return serializer._serialize(self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs) # type: ignore
396
396
 
397
397
  @classmethod
398
398
  def _infer_class_models(cls):
@@ -417,7 +417,7 @@ class Model(object):
417
417
  :raises: DeserializationError if something went wrong
418
418
  """
419
419
  deserializer = Deserializer(cls._infer_class_models())
420
- return deserializer(cls.__name__, data, content_type=content_type)
420
+ return deserializer(cls.__name__, data, content_type=content_type) # type: ignore
421
421
 
422
422
  @classmethod
423
423
  def from_dict(
@@ -447,7 +447,7 @@ class Model(object):
447
447
  if key_extractors is None
448
448
  else key_extractors
449
449
  )
450
- return deserializer(cls.__name__, data, content_type=content_type)
450
+ return deserializer(cls.__name__, data, content_type=content_type) # type: ignore
451
451
 
452
452
  @classmethod
453
453
  def _flatten_subtype(cls, key, objects):
@@ -16,6 +16,7 @@ from .._utils import (
16
16
  KNOWN_TYPES,
17
17
  get_body_type_for_description,
18
18
  JSON_REGEXP,
19
+ update_enum_value,
19
20
  )
20
21
  from .. import YamlUpdatePluginAutorest
21
22
 
@@ -88,24 +89,25 @@ def update_constant(yaml_data: Dict[str, Any]) -> Dict[str, Any]:
88
89
  return base
89
90
 
90
91
 
91
- def update_enum_value(yaml_data: Dict[str, Any]) -> Dict[str, Any]:
92
- return {
93
- "name": yaml_data["language"]["default"]["name"],
94
- "value": yaml_data["value"],
95
- "description": yaml_data["language"]["default"]["description"],
96
- }
97
-
98
-
99
92
  def update_enum(yaml_data: Dict[str, Any]) -> Dict[str, Any]:
100
93
  base = _update_type_base("enum", yaml_data)
101
94
  base.update(
102
95
  {
103
96
  "name": yaml_data["language"]["default"]["name"],
104
97
  "valueType": update_type(yaml_data["choiceType"]),
105
- "values": [update_enum_value(v) for v in yaml_data["choices"]],
98
+ "values": [],
106
99
  "description": yaml_data["language"]["default"]["description"],
107
100
  }
108
101
  )
102
+ for v in yaml_data["choices"]:
103
+ base["values"].append(
104
+ update_enum_value(
105
+ name=v["language"]["default"]["name"],
106
+ value=v["value"],
107
+ description=v["language"]["default"]["description"],
108
+ enum_type=base,
109
+ )
110
+ )
109
111
  return base
110
112
 
111
113
 
@@ -8,7 +8,7 @@
8
8
  import copy
9
9
  from typing import Callable, Dict, Any, List, Optional
10
10
 
11
- from .._utils import to_snake_case
11
+ from .._utils import to_snake_case, update_enum_value
12
12
  from .helpers import (
13
13
  add_redefined_builtin_info,
14
14
  pad_builtin_namespaces,
@@ -264,11 +264,12 @@ class PreProcessPlugin(YamlUpdatePlugin): # pylint: disable=abstract-method
264
264
  ).upper()
265
265
  if value["name"] != padded_name:
266
266
  values_to_add.append(
267
- {
268
- "description": value["description"],
269
- "name": padded_name,
270
- "value": value["value"],
271
- }
267
+ update_enum_value(
268
+ name=padded_name,
269
+ value=value["value"],
270
+ description=value["description"],
271
+ enum_type=value["enumType"],
272
+ )
272
273
  )
273
274
  type["values"].extend(values_to_add)
274
275
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.9.2",
3
+ "version": "6.9.3",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "main": "index.js",
6
6
  "repository": {