@autorest/python 6.38.1 → 6.39.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 (146) hide show
  1. package/README.md +2 -27
  2. package/autorest/codegen.py +0 -1
  3. package/autorest/jsonrpc/server.py +0 -3
  4. package/generator/build/lib/pygen/__init__.py +14 -23
  5. package/generator/build/lib/pygen/codegen/__init__.py +4 -4
  6. package/generator/build/lib/pygen/codegen/models/__init__.py +2 -2
  7. package/generator/build/lib/pygen/codegen/models/base.py +9 -12
  8. package/generator/build/lib/pygen/codegen/models/base_builder.py +4 -6
  9. package/generator/build/lib/pygen/codegen/models/client.py +61 -102
  10. package/generator/build/lib/pygen/codegen/models/code_model.py +29 -29
  11. package/generator/build/lib/pygen/codegen/models/combined_type.py +7 -7
  12. package/generator/build/lib/pygen/codegen/models/constant_type.py +4 -11
  13. package/generator/build/lib/pygen/codegen/models/credential_types.py +9 -11
  14. package/generator/build/lib/pygen/codegen/models/dictionary_type.py +7 -8
  15. package/generator/build/lib/pygen/codegen/models/enum_type.py +7 -7
  16. package/generator/build/lib/pygen/codegen/models/imports.py +24 -29
  17. package/generator/build/lib/pygen/codegen/models/list_type.py +15 -14
  18. package/generator/build/lib/pygen/codegen/models/lro_operation.py +6 -6
  19. package/generator/build/lib/pygen/codegen/models/lro_paging_operation.py +2 -2
  20. package/generator/build/lib/pygen/codegen/models/model_type.py +11 -11
  21. package/generator/build/lib/pygen/codegen/models/operation.py +26 -56
  22. package/generator/build/lib/pygen/codegen/models/operation_group.py +11 -22
  23. package/generator/build/lib/pygen/codegen/models/paging_operation.py +15 -19
  24. package/generator/build/lib/pygen/codegen/models/parameter.py +12 -21
  25. package/generator/build/lib/pygen/codegen/models/parameter_list.py +37 -39
  26. package/generator/build/lib/pygen/codegen/models/primitive_types.py +24 -18
  27. package/generator/build/lib/pygen/codegen/models/property.py +10 -10
  28. package/generator/build/lib/pygen/codegen/models/request_builder.py +7 -8
  29. package/generator/build/lib/pygen/codegen/models/request_builder_parameter.py +3 -3
  30. package/generator/build/lib/pygen/codegen/models/response.py +15 -40
  31. package/generator/build/lib/pygen/codegen/models/utils.py +2 -2
  32. package/generator/build/lib/pygen/codegen/serializers/__init__.py +26 -42
  33. package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +103 -100
  34. package/generator/build/lib/pygen/codegen/serializers/client_serializer.py +22 -25
  35. package/generator/build/lib/pygen/codegen/serializers/enum_serializer.py +2 -2
  36. package/generator/build/lib/pygen/codegen/serializers/general_serializer.py +49 -61
  37. package/generator/build/lib/pygen/codegen/serializers/import_serializer.py +6 -7
  38. package/generator/build/lib/pygen/codegen/serializers/model_init_serializer.py +1 -2
  39. package/generator/build/lib/pygen/codegen/serializers/model_serializer.py +15 -17
  40. package/generator/build/lib/pygen/codegen/serializers/operation_groups_serializer.py +3 -3
  41. package/generator/build/lib/pygen/codegen/serializers/operations_init_serializer.py +5 -6
  42. package/generator/build/lib/pygen/codegen/serializers/parameter_serializer.py +28 -18
  43. package/generator/build/lib/pygen/codegen/serializers/patch_serializer.py +1 -2
  44. package/generator/build/lib/pygen/codegen/serializers/request_builders_serializer.py +1 -2
  45. package/generator/build/lib/pygen/codegen/serializers/sample_serializer.py +9 -14
  46. package/generator/build/lib/pygen/codegen/serializers/test_serializer.py +7 -7
  47. package/generator/build/lib/pygen/codegen/serializers/utils.py +2 -2
  48. package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +30 -24
  49. package/generator/build/lib/pygen/codegen/templates/model_dpg.py.jinja2 +1 -1
  50. package/generator/build/lib/pygen/codegen/templates/operation_group.py.jinja2 +1 -11
  51. package/generator/build/lib/pygen/codegen/templates/operations_folder_init.py.jinja2 +1 -1
  52. package/generator/build/lib/pygen/codegen/templates/packaging_templates/CHANGELOG.md.jinja2 +2 -1
  53. package/generator/build/lib/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +1 -1
  54. package/generator/build/lib/pygen/codegen/templates/packaging_templates/pyproject.toml.jinja2 +13 -2
  55. package/generator/build/lib/pygen/codegen/templates/patch.py.jinja2 +1 -1
  56. package/generator/build/lib/pygen/codegen/templates/serialization.py.jinja2 +11 -13
  57. package/generator/build/lib/pygen/codegen/templates/utils.py.jinja2 +6 -6
  58. package/generator/build/lib/pygen/preprocess/__init__.py +47 -30
  59. package/generator/build/lib/pygen/preprocess/helpers.py +2 -2
  60. package/generator/build/lib/pygen/utils.py +6 -6
  61. package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
  62. package/generator/pygen/__init__.py +14 -23
  63. package/generator/pygen/codegen/__init__.py +4 -4
  64. package/generator/pygen/codegen/models/__init__.py +2 -2
  65. package/generator/pygen/codegen/models/base.py +9 -12
  66. package/generator/pygen/codegen/models/base_builder.py +4 -6
  67. package/generator/pygen/codegen/models/client.py +61 -102
  68. package/generator/pygen/codegen/models/code_model.py +29 -29
  69. package/generator/pygen/codegen/models/combined_type.py +7 -7
  70. package/generator/pygen/codegen/models/constant_type.py +4 -11
  71. package/generator/pygen/codegen/models/credential_types.py +9 -11
  72. package/generator/pygen/codegen/models/dictionary_type.py +7 -8
  73. package/generator/pygen/codegen/models/enum_type.py +7 -7
  74. package/generator/pygen/codegen/models/imports.py +24 -29
  75. package/generator/pygen/codegen/models/list_type.py +15 -14
  76. package/generator/pygen/codegen/models/lro_operation.py +6 -6
  77. package/generator/pygen/codegen/models/lro_paging_operation.py +2 -2
  78. package/generator/pygen/codegen/models/model_type.py +11 -11
  79. package/generator/pygen/codegen/models/operation.py +26 -56
  80. package/generator/pygen/codegen/models/operation_group.py +11 -22
  81. package/generator/pygen/codegen/models/paging_operation.py +15 -19
  82. package/generator/pygen/codegen/models/parameter.py +12 -21
  83. package/generator/pygen/codegen/models/parameter_list.py +37 -39
  84. package/generator/pygen/codegen/models/primitive_types.py +24 -18
  85. package/generator/pygen/codegen/models/property.py +10 -10
  86. package/generator/pygen/codegen/models/request_builder.py +7 -8
  87. package/generator/pygen/codegen/models/request_builder_parameter.py +3 -3
  88. package/generator/pygen/codegen/models/response.py +15 -40
  89. package/generator/pygen/codegen/models/utils.py +2 -2
  90. package/generator/pygen/codegen/serializers/__init__.py +26 -42
  91. package/generator/pygen/codegen/serializers/builder_serializer.py +103 -100
  92. package/generator/pygen/codegen/serializers/client_serializer.py +22 -25
  93. package/generator/pygen/codegen/serializers/enum_serializer.py +2 -2
  94. package/generator/pygen/codegen/serializers/general_serializer.py +49 -61
  95. package/generator/pygen/codegen/serializers/import_serializer.py +6 -7
  96. package/generator/pygen/codegen/serializers/model_init_serializer.py +1 -2
  97. package/generator/pygen/codegen/serializers/model_serializer.py +15 -17
  98. package/generator/pygen/codegen/serializers/operation_groups_serializer.py +3 -3
  99. package/generator/pygen/codegen/serializers/operations_init_serializer.py +5 -6
  100. package/generator/pygen/codegen/serializers/parameter_serializer.py +28 -18
  101. package/generator/pygen/codegen/serializers/patch_serializer.py +1 -2
  102. package/generator/pygen/codegen/serializers/request_builders_serializer.py +1 -2
  103. package/generator/pygen/codegen/serializers/sample_serializer.py +9 -14
  104. package/generator/pygen/codegen/serializers/test_serializer.py +7 -7
  105. package/generator/pygen/codegen/serializers/utils.py +2 -2
  106. package/generator/pygen/codegen/templates/model_base.py.jinja2 +30 -24
  107. package/generator/pygen/codegen/templates/model_dpg.py.jinja2 +1 -1
  108. package/generator/pygen/codegen/templates/operation_group.py.jinja2 +1 -11
  109. package/generator/pygen/codegen/templates/operations_folder_init.py.jinja2 +1 -1
  110. package/generator/pygen/codegen/templates/packaging_templates/CHANGELOG.md.jinja2 +2 -1
  111. package/generator/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +1 -1
  112. package/generator/pygen/codegen/templates/packaging_templates/pyproject.toml.jinja2 +13 -2
  113. package/generator/pygen/codegen/templates/patch.py.jinja2 +1 -1
  114. package/generator/pygen/codegen/templates/serialization.py.jinja2 +11 -13
  115. package/generator/pygen/codegen/templates/utils.py.jinja2 +6 -6
  116. package/generator/pygen/preprocess/__init__.py +47 -30
  117. package/generator/pygen/preprocess/helpers.py +2 -2
  118. package/generator/pygen/utils.py +6 -6
  119. package/generator/pygen.egg-info/SOURCES.txt +0 -2
  120. package/package.json +2 -2
  121. package/scripts/__pycache__/venvtools.cpython-310.pyc +0 -0
  122. package/autorest/multiapi/__init__.py +0 -185
  123. package/autorest/multiapi/models/__init__.py +0 -16
  124. package/autorest/multiapi/models/client.py +0 -68
  125. package/autorest/multiapi/models/code_model.py +0 -142
  126. package/autorest/multiapi/models/config.py +0 -24
  127. package/autorest/multiapi/models/constant_global_parameter.py +0 -11
  128. package/autorest/multiapi/models/global_parameter.py +0 -34
  129. package/autorest/multiapi/models/global_parameters.py +0 -53
  130. package/autorest/multiapi/models/imports.py +0 -181
  131. package/autorest/multiapi/models/mixin_operation.py +0 -38
  132. package/autorest/multiapi/models/operation_group.py +0 -29
  133. package/autorest/multiapi/models/operation_mixin_group.py +0 -89
  134. package/autorest/multiapi/serializers/__init__.py +0 -145
  135. package/autorest/multiapi/serializers/import_serializer.py +0 -181
  136. package/autorest/multiapi/templates/multiapi_config.py.jinja2 +0 -89
  137. package/autorest/multiapi/templates/multiapi_init.py.jinja2 +0 -22
  138. package/autorest/multiapi/templates/multiapi_models.py.jinja2 +0 -9
  139. package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +0 -39
  140. package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +0 -163
  141. package/autorest/multiapi/templates/multiapi_version.py.jinja2 +0 -8
  142. package/autorest/multiapi/utils.py +0 -51
  143. package/generator/build/lib/pygen/codegen/serializers/metadata_serializer.py +0 -216
  144. package/generator/build/lib/pygen/codegen/templates/metadata.json.jinja2 +0 -167
  145. package/generator/pygen/codegen/serializers/metadata_serializer.py +0 -216
  146. package/generator/pygen/codegen/templates/metadata.json.jinja2 +0 -167
@@ -3,9 +3,9 @@
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, Optional, TYPE_CHECKING, List
6
+ from typing import Any, Optional, TYPE_CHECKING
7
7
  from .base import BaseType
8
- from .imports import FileImport, ImportType, TypingSection
8
+ from .imports import FileImport
9
9
 
10
10
  if TYPE_CHECKING:
11
11
  from .code_model import CodeModel
@@ -23,7 +23,7 @@ class DictionaryType(BaseType):
23
23
 
24
24
  def __init__(
25
25
  self,
26
- yaml_data: Dict[str, Any],
26
+ yaml_data: dict[str, Any],
27
27
  code_model: "CodeModel",
28
28
  element_type: BaseType,
29
29
  ) -> None:
@@ -48,7 +48,7 @@ class DictionaryType(BaseType):
48
48
  :return: The type annotation for this schema
49
49
  :rtype: str
50
50
  """
51
- return f"Dict[str, {self.element_type.type_annotation(**kwargs)}]"
51
+ return f"dict[str, {self.element_type.type_annotation(**kwargs)}]"
52
52
 
53
53
  def description(self, *, is_operation_file: bool) -> str:
54
54
  return "" if is_operation_file else self.yaml_data.get("description", "")
@@ -79,7 +79,7 @@ class DictionaryType(BaseType):
79
79
  )
80
80
  }
81
81
 
82
- def get_polymorphic_subtypes(self, polymorphic_subtypes: List["ModelType"]) -> None:
82
+ def get_polymorphic_subtypes(self, polymorphic_subtypes: list["ModelType"]) -> None:
83
83
  from .model_type import ModelType
84
84
 
85
85
  if isinstance(self.element_type, ModelType):
@@ -90,7 +90,7 @@ class DictionaryType(BaseType):
90
90
  polymorphic_subtypes.append(self.element_type)
91
91
 
92
92
  @classmethod
93
- def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "DictionaryType":
93
+ def from_yaml(cls, yaml_data: dict[str, Any], code_model: "CodeModel") -> "DictionaryType":
94
94
  """Constructs a DictionaryType from yaml data.
95
95
 
96
96
  :param yaml_data: the yaml data from which we will construct this schema
@@ -99,7 +99,7 @@ class DictionaryType(BaseType):
99
99
  :return: A created DictionaryType
100
100
  :rtype: ~autorest.models.DictionaryType
101
101
  """
102
- element_schema: Dict[str, Any] = yaml_data["elementType"]
102
+ element_schema: dict[str, Any] = yaml_data["elementType"]
103
103
 
104
104
  from . import build_type # pylint: disable=import-outside-toplevel
105
105
 
@@ -113,7 +113,6 @@ class DictionaryType(BaseType):
113
113
 
114
114
  def imports(self, **kwargs: Any) -> FileImport:
115
115
  file_import = FileImport(self.code_model)
116
- file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB, TypingSection.CONDITIONAL)
117
116
  file_import.merge(self.element_type.imports(**kwargs))
118
117
  return file_import
119
118
 
@@ -3,7 +3,7 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- from typing import Any, Dict, List, TYPE_CHECKING, Optional, cast
6
+ from typing import Any, TYPE_CHECKING, Optional, cast
7
7
 
8
8
  from .base import BaseType
9
9
  from .imports import FileImport, ImportType, TypingSection
@@ -24,7 +24,7 @@ class EnumValue(BaseType):
24
24
 
25
25
  def __init__(
26
26
  self,
27
- yaml_data: Dict[str, Any],
27
+ yaml_data: dict[str, Any],
28
28
  code_model: "CodeModel",
29
29
  enum_type: "EnumType",
30
30
  value_type: BaseType,
@@ -94,7 +94,7 @@ class EnumValue(BaseType):
94
94
  return file_import
95
95
 
96
96
  @classmethod
97
- def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "EnumValue":
97
+ def from_yaml(cls, yaml_data: dict[str, Any], code_model: "CodeModel") -> "EnumValue":
98
98
  """Constructs an EnumValue from yaml data.
99
99
 
100
100
  :param yaml_data: the yaml data from which we will construct this object
@@ -127,9 +127,9 @@ class EnumType(BaseType):
127
127
 
128
128
  def __init__(
129
129
  self,
130
- yaml_data: Dict[str, Any],
130
+ yaml_data: dict[str, Any],
131
131
  code_model: "CodeModel",
132
- values: List["EnumValue"],
132
+ values: list["EnumValue"],
133
133
  value_type: BaseType,
134
134
  ) -> None:
135
135
  super().__init__(yaml_data=yaml_data, code_model=code_model)
@@ -219,12 +219,12 @@ class EnumType(BaseType):
219
219
  def instance_check_template(self) -> str:
220
220
  return self.value_type.instance_check_template
221
221
 
222
- def fill_instance_from_yaml(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
222
+ def fill_instance_from_yaml(self, yaml_data: dict[str, Any], code_model: "CodeModel") -> None:
223
223
  for value in yaml_data["values"]:
224
224
  self.values.append(EnumValue.from_yaml(value, code_model))
225
225
 
226
226
  @classmethod
227
- def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "EnumType":
227
+ def from_yaml(cls, yaml_data: dict[str, Any], code_model: "CodeModel") -> "EnumType":
228
228
  raise ValueError(
229
229
  "You shouldn't call from_yaml for EnumType to avoid recursion. "
230
230
  "Please initial a blank EnumType, then call .fill_instance_from_yaml on the created type."
@@ -4,8 +4,7 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  from enum import Enum, auto
7
- from typing import Dict, List, Optional, Tuple, Union, Set, TYPE_CHECKING
8
- from .._utils import get_parent_namespace
7
+ from typing import Optional, Union, TYPE_CHECKING
9
8
 
10
9
  if TYPE_CHECKING:
11
10
  from .code_model import CodeModel
@@ -46,7 +45,7 @@ class ImportModel:
46
45
  *,
47
46
  submodule_name: Optional[str] = None,
48
47
  alias: Optional[str] = None,
49
- version_modules: Optional[Tuple[Tuple[Tuple[int, int], str, Optional[str]]]] = None,
48
+ version_modules: Optional[tuple[tuple[tuple[int, int], str, Optional[str]]]] = None,
50
49
  ):
51
50
  self.typing_section = typing_section
52
51
  self.import_type = import_type
@@ -90,10 +89,10 @@ class TypeDefinition:
90
89
 
91
90
  class FileImport:
92
91
  def __init__(self, code_model: "CodeModel") -> None:
93
- self.imports: List[ImportModel] = []
92
+ self.imports: list[ImportModel] = []
94
93
  self.code_model = code_model
95
94
  # has sync and async type definitions
96
- self.type_definitions: Dict[str, TypeDefinition] = {}
95
+ self.type_definitions: dict[str, TypeDefinition] = {}
97
96
  self.core_library = self.code_model.core_library
98
97
 
99
98
  def _append_import(self, import_model: ImportModel) -> None:
@@ -114,7 +113,7 @@ class FileImport:
114
113
  ):
115
114
  self.imports.append(import_model)
116
115
 
117
- def get_imports_from_section(self, typing_section: TypingSection) -> List[ImportModel]:
116
+ def get_imports_from_section(self, typing_section: TypingSection) -> list[ImportModel]:
118
117
  return [i for i in self.imports if i.typing_section == typing_section]
119
118
 
120
119
  def add_submodule_import(
@@ -124,7 +123,7 @@ class FileImport:
124
123
  import_type: ImportType,
125
124
  typing_section: TypingSection = TypingSection.REGULAR,
126
125
  alias: Optional[str] = None,
127
- version_modules: Optional[Tuple[Tuple[Tuple[int, int], str, Optional[str]]]] = None,
126
+ version_modules: Optional[tuple[tuple[tuple[int, int], str, Optional[str]]]] = None,
128
127
  ) -> None:
129
128
  """Add an import to this import block."""
130
129
  self._append_import(
@@ -167,7 +166,7 @@ class FileImport:
167
166
  """Merge the given file import format."""
168
167
  for i in file_import.imports:
169
168
  self._append_import(i)
170
- self.type_definitions.update(file_import.type_definitions)
169
+ self.type_definitions |= file_import.type_definitions
171
170
 
172
171
  def add_mutable_mapping_import(self) -> None:
173
172
  self.add_submodule_import("collections.abc", "MutableMapping", ImportType.STDLIB)
@@ -180,21 +179,21 @@ class FileImport:
180
179
 
181
180
  def to_dict(
182
181
  self,
183
- ) -> Dict[
182
+ ) -> dict[
184
183
  TypingSection,
185
- Dict[
184
+ dict[
186
185
  ImportType,
187
- Dict[
186
+ dict[
188
187
  str,
189
- Set[
188
+ set[
190
189
  Optional[
191
190
  Union[
192
191
  str,
193
- Tuple[str, str],
194
- Tuple[
192
+ tuple[str, str],
193
+ tuple[
195
194
  str,
196
195
  Optional[str],
197
- Tuple[Tuple[Tuple[int, int], str, Optional[str]]],
196
+ tuple[tuple[tuple[int, int], str, Optional[str]]],
198
197
  ],
199
198
  ]
200
199
  ]
@@ -202,21 +201,21 @@ class FileImport:
202
201
  ],
203
202
  ],
204
203
  ]:
205
- retval: Dict[
204
+ retval: dict[
206
205
  TypingSection,
207
- Dict[
206
+ dict[
208
207
  ImportType,
209
- Dict[
208
+ dict[
210
209
  str,
211
- Set[
210
+ set[
212
211
  Optional[
213
212
  Union[
214
213
  str,
215
- Tuple[str, str],
216
- Tuple[
214
+ tuple[str, str],
215
+ tuple[
217
216
  str,
218
217
  Optional[str],
219
- Tuple[Tuple[Tuple[int, int], str, Optional[str]]],
218
+ tuple[tuple[tuple[int, int], str, Optional[str]]],
220
219
  ],
221
220
  ]
222
221
  ]
@@ -228,11 +227,11 @@ class FileImport:
228
227
  name_import: Optional[
229
228
  Union[
230
229
  str,
231
- Tuple[str, str],
232
- Tuple[
230
+ tuple[str, str],
231
+ tuple[
233
232
  str,
234
233
  Optional[str],
235
- Tuple[Tuple[Tuple[int, int], str, Optional[str]]],
234
+ tuple[tuple[tuple[int, int], str, Optional[str]]],
236
235
  ],
237
236
  ]
238
237
  ] = None
@@ -265,10 +264,6 @@ class FileImport:
265
264
  else:
266
265
  # _utils/serialization.py is always in root namespace
267
266
  imported_namespace = f"{self.code_model.namespace}._utils"
268
- if self.code_model.options["multiapi"]:
269
- # for multiapi, the namespace is azure.mgmt.xxx.v20XX_XX_XX
270
- # while _utils/serialization.py is in azure.mgmt.xxx
271
- imported_namespace = f"{get_parent_namespace(imported_namespace)}._utils"
272
267
  if msrest_import_type == MsrestImportType.Module:
273
268
  self.add_submodule_import(
274
269
  self.code_model.get_relative_import_path(serialize_namespace, imported_namespace),
@@ -3,9 +3,9 @@
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, Optional, Union, TYPE_CHECKING, List
6
+ from typing import Any, Optional, Union, TYPE_CHECKING
7
7
  from .base import BaseType
8
- from .imports import FileImport, ImportType, TypingSection
8
+ from .imports import FileImport
9
9
 
10
10
  if TYPE_CHECKING:
11
11
  from .code_model import CodeModel
@@ -15,7 +15,7 @@ if TYPE_CHECKING:
15
15
  class ListType(BaseType):
16
16
  def __init__(
17
17
  self,
18
- yaml_data: Dict[str, Any],
18
+ yaml_data: dict[str, Any],
19
19
  code_model: "CodeModel",
20
20
  element_type: BaseType,
21
21
  ) -> None:
@@ -40,7 +40,14 @@ class ListType(BaseType):
40
40
  ):
41
41
  # this means we're version tolerant XML, we just return the XML element
42
42
  return self.element_type.type_annotation(**kwargs)
43
- return f"List[{self.element_type.type_annotation(**kwargs)}]"
43
+ has_operation_named_list = any(
44
+ o.name.lower() == "list"
45
+ for c in self.code_model.clients
46
+ for og in c.operation_groups
47
+ for o in og.operations
48
+ )
49
+ list_type = "List" if has_operation_named_list and kwargs.get("is_operation_file") else "list"
50
+ return f"{list_type}[{self.element_type.type_annotation(**kwargs)}]"
44
51
 
45
52
  def description(self, *, is_operation_file: bool) -> str:
46
53
  return "" if is_operation_file else self.yaml_data.get("description", "")
@@ -80,8 +87,8 @@ class ListType(BaseType):
80
87
  return f"list of {self.element_type.docstring_text(**kwargs)}"
81
88
 
82
89
  @property
83
- def validation(self) -> Optional[Dict[str, Union[bool, int, str]]]:
84
- validation: Dict[str, Union[bool, int, str]] = {}
90
+ def validation(self) -> Optional[dict[str, Union[bool, int, str]]]:
91
+ validation: dict[str, Union[bool, int, str]] = {}
85
92
  if self.max_items:
86
93
  validation["max_items"] = self.max_items
87
94
  validation["min_items"] = self.min_items or 0
@@ -102,7 +109,7 @@ class ListType(BaseType):
102
109
  )
103
110
  ]
104
111
 
105
- def get_polymorphic_subtypes(self, polymorphic_subtypes: List["ModelType"]) -> None:
112
+ def get_polymorphic_subtypes(self, polymorphic_subtypes: list["ModelType"]) -> None:
106
113
  from .model_type import ModelType
107
114
 
108
115
  if isinstance(self.element_type, ModelType):
@@ -117,7 +124,7 @@ class ListType(BaseType):
117
124
  return "isinstance({}, list)"
118
125
 
119
126
  @classmethod
120
- def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "ListType":
127
+ def from_yaml(cls, yaml_data: dict[str, Any], code_model: "CodeModel") -> "ListType":
121
128
  from . import build_type
122
129
 
123
130
  return cls(
@@ -128,12 +135,6 @@ class ListType(BaseType):
128
135
 
129
136
  def imports(self, **kwargs: Any) -> FileImport:
130
137
  file_import = FileImport(self.code_model)
131
- if not (
132
- self.code_model.options["version-tolerant"]
133
- and self.element_type.is_xml
134
- and not self.code_model.options["models-mode"]
135
- ):
136
- file_import.add_submodule_import("typing", "List", ImportType.STDLIB, TypingSection.CONDITIONAL)
137
138
  file_import.merge(self.element_type.imports(**kwargs))
138
139
  return file_import
139
140
 
@@ -3,7 +3,7 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- from typing import Any, Dict, Optional, List, TYPE_CHECKING, TypeVar, Union
6
+ from typing import Any, Optional, TYPE_CHECKING, TypeVar, Union
7
7
  from .imports import FileImport
8
8
  from .operation import OperationBase, Operation
9
9
  from .response import LROPagingResponse, LROResponse, Response
@@ -22,16 +22,16 @@ LROResponseType = TypeVar("LROResponseType", bound=Union[LROResponse, LROPagingR
22
22
  class LROOperationBase(OperationBase[LROResponseType]):
23
23
  def __init__(
24
24
  self,
25
- yaml_data: Dict[str, Any],
25
+ yaml_data: dict[str, Any],
26
26
  code_model: "CodeModel",
27
27
  client: "Client",
28
28
  name: str,
29
29
  request_builder: RequestBuilder,
30
30
  parameters: ParameterList,
31
- responses: List[LROResponseType],
32
- exceptions: List[Response],
31
+ responses: list[LROResponseType],
32
+ exceptions: list[Response],
33
33
  *,
34
- overloads: Optional[List[Operation]] = None,
34
+ overloads: Optional[list[Operation]] = None,
35
35
  ) -> None:
36
36
  super().__init__(
37
37
  code_model=code_model,
@@ -46,7 +46,7 @@ class LROOperationBase(OperationBase[LROResponseType]):
46
46
  )
47
47
  if not self.name.lstrip("_").startswith("begin"):
48
48
  self.name = ("_begin" if self.internal else "begin_") + self.name
49
- self.lro_options: Dict[str, Any] = self.yaml_data.get("lroOptions", {})
49
+ self.lro_options: dict[str, Any] = self.yaml_data.get("lroOptions", {})
50
50
  self._initial_operation: Optional["OperationType"] = None
51
51
 
52
52
  @property
@@ -3,7 +3,7 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- from typing import Any, List, Union
6
+ from typing import Any, Union
7
7
  from .imports import FileImport
8
8
  from .lro_operation import LROOperationBase
9
9
  from .paging_operation import PagingOperationBase
@@ -12,7 +12,7 @@ from .response import LROPagingResponse, Response
12
12
 
13
13
  class LROPagingOperation(LROOperationBase[LROPagingResponse], PagingOperationBase[LROPagingResponse]):
14
14
  @property
15
- def success_status_codes(self) -> List[Union[int, str, List[int]]]:
15
+ def success_status_codes(self) -> list[Union[int, str, list[int]]]:
16
16
  """The list of all successfull status code."""
17
17
  return [200]
18
18
 
@@ -5,7 +5,7 @@
5
5
  # --------------------------------------------------------------------------
6
6
  from enum import Enum
7
7
  from collections import OrderedDict
8
- from typing import Any, Dict, List, Optional, TYPE_CHECKING, cast
8
+ from typing import Any, Optional, TYPE_CHECKING, cast
9
9
  import sys
10
10
  from .utils import add_to_pylint_disable, NamespaceType
11
11
  from .base import BaseType
@@ -36,7 +36,7 @@ class UsageFlags(Enum):
36
36
  Xml = 512
37
37
 
38
38
 
39
- def _get_properties(type: "ModelType", properties: List[Property]) -> List[Property]:
39
+ def _get_properties(type: "ModelType", properties: list[Property]) -> list[Property]:
40
40
  for parent in type.parents:
41
41
  # here we're adding the properties from our parents
42
42
 
@@ -61,12 +61,12 @@ class ModelType(BaseType): # pylint: disable=too-many-instance-attributes, too-
61
61
 
62
62
  def __init__(
63
63
  self,
64
- yaml_data: Dict[str, Any],
64
+ yaml_data: dict[str, Any],
65
65
  code_model: "CodeModel",
66
66
  *,
67
- properties: Optional[List[Property]] = None,
68
- parents: Optional[List["ModelType"]] = None,
69
- discriminated_subtypes: Optional[Dict[str, "ModelType"]] = None,
67
+ properties: Optional[list[Property]] = None,
68
+ parents: Optional[list["ModelType"]] = None,
69
+ discriminated_subtypes: Optional[dict[str, "ModelType"]] = None,
70
70
  ) -> None:
71
71
  super().__init__(yaml_data=yaml_data, code_model=code_model)
72
72
  self.name: str = self.yaml_data["name"]
@@ -96,7 +96,7 @@ class ModelType(BaseType): # pylint: disable=too-many-instance-attributes, too-
96
96
  return None
97
97
 
98
98
  @property
99
- def flattened_items(self) -> List[str]:
99
+ def flattened_items(self) -> list[str]:
100
100
  return [
101
101
  item.client_name
102
102
  for prop in self.properties
@@ -141,7 +141,7 @@ class ModelType(BaseType): # pylint: disable=too-many-instance-attributes, too-
141
141
  return super().xml_serialization_ctxt
142
142
 
143
143
  @property
144
- def discriminated_subtypes_name_mapping(self) -> Dict[str, str]:
144
+ def discriminated_subtypes_name_mapping(self) -> dict[str, str]:
145
145
  return {k: v.name for k, v in self.discriminated_subtypes.items()}
146
146
 
147
147
  def get_json_template_representation(
@@ -181,7 +181,7 @@ class ModelType(BaseType): # pylint: disable=too-many-instance-attributes, too-
181
181
  )
182
182
  )
183
183
 
184
- def get_polymorphic_subtypes(self, polymorphic_subtypes: List["ModelType"]) -> None:
184
+ def get_polymorphic_subtypes(self, polymorphic_subtypes: list["ModelType"]) -> None:
185
185
  is_polymorphic_subtype = self.discriminator_value and not self.discriminated_subtypes
186
186
  if self._got_polymorphic_subtypes:
187
187
  return
@@ -195,13 +195,13 @@ class ModelType(BaseType): # pylint: disable=too-many-instance-attributes, too-
195
195
  self._got_polymorphic_subtypes = False
196
196
 
197
197
  @classmethod
198
- def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "ModelType":
198
+ def from_yaml(cls, yaml_data: dict[str, Any], code_model: "CodeModel") -> "ModelType":
199
199
  raise ValueError(
200
200
  "You shouldn't call from_yaml for ModelType to avoid recursion. "
201
201
  "Please initial a blank ModelType, then call .fill_instance_from_yaml on the created type."
202
202
  )
203
203
 
204
- def fill_instance_from_yaml(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
204
+ def fill_instance_from_yaml(self, yaml_data: dict[str, Any], code_model: "CodeModel") -> None:
205
205
  from . import build_type
206
206
 
207
207
  self.parents = [cast(ModelType, build_type(bm, code_model)) for bm in yaml_data.get("parents", [])]
@@ -4,8 +4,6 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  from typing import (
7
- Dict,
8
- List,
9
7
  Any,
10
8
  Optional,
11
9
  Union,
@@ -61,14 +59,14 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
61
59
  ):
62
60
  def __init__(
63
61
  self,
64
- yaml_data: Dict[str, Any],
62
+ yaml_data: dict[str, Any],
65
63
  code_model: "CodeModel",
66
64
  client: "Client",
67
65
  name: str,
68
66
  request_builder: Union[RequestBuilder, OverloadedRequestBuilder],
69
67
  parameters: ParameterList,
70
- responses: List[ResponseType],
71
- exceptions: List[Response],
68
+ responses: list[ResponseType],
69
+ exceptions: list[Response],
72
70
  *,
73
71
  overloads: Optional[Sequence["Operation"]] = None,
74
72
  ) -> None:
@@ -204,61 +202,18 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
204
202
  return None if self.code_model.options["models-mode"] == "dpg" else "'object'"
205
203
 
206
204
  @property
207
- def non_default_errors(self) -> List[Response]:
205
+ def non_default_errors(self) -> list[Response]:
208
206
  return [
209
207
  e for e in self.exceptions if "default" not in e.status_codes and e.type and isinstance(e.type, ModelType)
210
208
  ]
211
209
 
212
- def _imports_shared(self, async_mode: bool, **kwargs: Any) -> FileImport:
213
- file_import = FileImport(self.code_model)
214
- file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
215
-
216
- response_types = [r.type_annotation(async_mode=async_mode, **kwargs) for r in self.responses if r.type]
217
- if len(set(response_types)) > 1:
218
- file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL)
219
- if self.added_on:
220
- serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
221
- file_import.add_submodule_import(
222
- self.code_model.get_relative_import_path(serialize_namespace, module_name="_validation"),
223
- "api_version_validation",
224
- ImportType.LOCAL,
225
- )
226
- return file_import
227
-
228
210
  @property
229
211
  def need_import_iobase(self) -> bool:
230
212
  return self.parameters.has_body and isinstance(self.parameters.body_parameter.type, CombinedType)
231
213
 
232
- def imports_for_multiapi(self, async_mode: bool, **kwargs: Any) -> FileImport:
233
- if self.abstract:
234
- return FileImport(self.code_model)
235
- file_import = self._imports_shared(async_mode, **kwargs)
236
- for param in self.parameters.method:
237
- file_import.merge(
238
- param.imports_for_multiapi(
239
- async_mode,
240
- need_import_iobase=self.need_import_iobase,
241
- **kwargs,
242
- )
243
- )
244
- for response in self.responses:
245
- file_import.merge(
246
- response.imports_for_multiapi(
247
- async_mode=async_mode, need_import_iobase=self.need_import_iobase, **kwargs
248
- )
249
- )
250
- if self.code_model.options["models-mode"]:
251
- for exception in self.exceptions:
252
- file_import.merge(
253
- exception.imports_for_multiapi(
254
- async_mode=async_mode, need_import_iobase=self.need_import_iobase, **kwargs
255
- )
256
- )
257
- return file_import
258
-
259
214
  @staticmethod
260
215
  def has_kwargs_to_pop_with_default(
261
- kwargs_to_pop: List[
216
+ kwargs_to_pop: list[
262
217
  Union[
263
218
  Parameter,
264
219
  RequestBuilderParameter,
@@ -326,7 +281,19 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
326
281
  return FileImport(self.code_model)
327
282
 
328
283
  serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
329
- file_import = self._imports_shared(async_mode, **kwargs)
284
+ file_import = FileImport(self.code_model)
285
+ file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
286
+
287
+ response_types = [r.type_annotation(async_mode=async_mode, **kwargs) for r in self.responses if r.type]
288
+ if len(set(response_types)) > 1:
289
+ file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL)
290
+ if self.added_on:
291
+ serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
292
+ file_import.add_submodule_import(
293
+ self.code_model.get_relative_import_path(serialize_namespace, module_name="_validation"),
294
+ "api_version_validation",
295
+ ImportType.LOCAL,
296
+ )
330
297
 
331
298
  for param in self.parameters.method:
332
299
  file_import.merge(
@@ -427,7 +394,6 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
427
394
  file_import.add_submodule_import("rest", "HttpRequest", ImportType.SDKCORE)
428
395
  file_import.add_submodule_import("typing", "Callable", ImportType.STDLIB, TypingSection.CONDITIONAL)
429
396
  file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL)
430
- file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB, TypingSection.CONDITIONAL)
431
397
  file_import.add_submodule_import("typing", "TypeVar", ImportType.STDLIB, TypingSection.CONDITIONAL)
432
398
  if self.code_model.options["tracing"] and self.want_tracing and not async_mode:
433
399
  file_import.add_submodule_import(
@@ -438,6 +404,10 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
438
404
  file_import.merge(self.get_request_builder_import(self.request_builder, async_mode, serialize_namespace))
439
405
  if self.overloads:
440
406
  file_import.add_submodule_import("typing", "overload", ImportType.STDLIB)
407
+ if self.name == "list":
408
+ # if there is a function named `list` we have to make sure there's no conflict with the built-in `list`
409
+ # not doing for dict or set yet, though we might have to later
410
+ file_import.define_mypy_type("List", "list")
441
411
  if self.code_model.options["models-mode"] == "dpg":
442
412
  relative_path = self.code_model.get_relative_import_path(
443
413
  serialize_namespace, module_name="_utils.model_base"
@@ -479,7 +449,7 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
479
449
  raise ValueError(f"Incorrect status code {status_code}, operation {self.name}") from exc
480
450
 
481
451
  @property
482
- def success_status_codes(self) -> List[Union[int, str, List[int]]]:
452
+ def success_status_codes(self) -> list[Union[int, str, list[int]]]:
483
453
  """The list of all successfull status code."""
484
454
  return sorted([code for response in self.responses for code in response.status_codes])
485
455
 
@@ -499,13 +469,13 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
499
469
  return any(r.is_stream_response for r in self.responses)
500
470
 
501
471
  @classmethod
502
- def get_request_builder(cls, yaml_data: Dict[str, Any], client: "Client"):
472
+ def get_request_builder(cls, yaml_data: dict[str, Any], client: "Client"):
503
473
  return client.lookup_request_builder(id(yaml_data))
504
474
 
505
475
  @classmethod
506
476
  def from_yaml(
507
477
  cls,
508
- yaml_data: Dict[str, Any],
478
+ yaml_data: dict[str, Any],
509
479
  code_model: "CodeModel",
510
480
  client: "Client",
511
481
  ):
@@ -548,7 +518,7 @@ class Operation(OperationBase[Response]):
548
518
  return file_import
549
519
 
550
520
 
551
- def get_operation(yaml_data: Dict[str, Any], code_model: "CodeModel", client: "Client") -> "OperationType":
521
+ def get_operation(yaml_data: dict[str, Any], code_model: "CodeModel", client: "Client") -> "OperationType":
552
522
  if yaml_data["discriminator"] == "lropaging":
553
523
  from .lro_paging_operation import LROPagingOperation as OperationCls
554
524
  elif yaml_data["discriminator"] == "lro":