@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
@@ -4,7 +4,7 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  from pathlib import Path
7
- from typing import List, Dict, Any, Set, Union, Literal, Optional, cast
7
+ from typing import Any, Union, Literal, Optional, cast
8
8
 
9
9
  from .base import BaseType
10
10
  from .enum_type import EnumType
@@ -22,7 +22,7 @@ def _is_legacy(options) -> bool:
22
22
  return not (options.get("version-tolerant") or options.get("low-level-client"))
23
23
 
24
24
 
25
- def get_all_operation_groups_recursively(clients: List[Client]) -> List[OperationGroup]:
25
+ def get_all_operation_groups_recursively(clients: list[Client]) -> list[OperationGroup]:
26
26
  operation_groups = []
27
27
  queue = []
28
28
  for client in clients:
@@ -37,10 +37,10 @@ def get_all_operation_groups_recursively(clients: List[Client]) -> List[Operatio
37
37
  class ClientNamespaceType:
38
38
  def __init__(
39
39
  self,
40
- clients: Optional[List[Client]] = None,
41
- models: Optional[List[ModelType]] = None,
42
- enums: Optional[List[EnumType]] = None,
43
- operation_groups: Optional[List[OperationGroup]] = None,
40
+ clients: Optional[list[Client]] = None,
41
+ models: Optional[list[ModelType]] = None,
42
+ enums: Optional[list[EnumType]] = None,
43
+ operation_groups: Optional[list[OperationGroup]] = None,
44
44
  ):
45
45
  self.clients = clients or []
46
46
  self.models = models or []
@@ -73,34 +73,34 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
73
73
 
74
74
  def __init__(
75
75
  self,
76
- yaml_data: Dict[str, Any],
76
+ yaml_data: dict[str, Any],
77
77
  options: OptionsDict,
78
78
  ) -> None:
79
79
  self.yaml_data = yaml_data
80
80
  self.options = options
81
81
  self.namespace = self.yaml_data["namespace"]
82
- self.types_map: Dict[int, BaseType] = {} # map yaml id to schema
83
- self._model_types: List[ModelType] = []
82
+ self.types_map: dict[int, BaseType] = {} # map yaml id to schema
83
+ self._model_types: list[ModelType] = []
84
84
  from . import build_type
85
85
 
86
86
  for type_yaml in yaml_data.get("types", []):
87
87
  build_type(yaml_data=type_yaml, code_model=self)
88
- self.clients: List[Client] = [
88
+ self.clients: list[Client] = [
89
89
  Client.from_yaml(client_yaml_data, self) for client_yaml_data in yaml_data["clients"]
90
90
  ]
91
91
  if self.options["models-mode"] and self.model_types:
92
92
  self.sort_model_types()
93
- self.named_unions: List[CombinedType] = [
93
+ self.named_unions: list[CombinedType] = [
94
94
  t for t in self.types_map.values() if isinstance(t, CombinedType) and t.name
95
95
  ]
96
96
  self.cross_language_package_id = self.yaml_data.get("crossLanguagePackageId")
97
97
  self.for_test: bool = False
98
98
  # key is typespec namespace, value is models/clients/opeartion_groups/enums cache in the namespace
99
- self._client_namespace_types: Dict[str, ClientNamespaceType] = {}
99
+ self._client_namespace_types: dict[str, ClientNamespaceType] = {}
100
100
  self.has_subnamespace = False
101
- self._operations_folder_name: Dict[str, str] = {}
102
- self._relative_import_path: Dict[str, str] = {}
103
- self.metadata: Dict[str, Any] = yaml_data.get("metadata", {})
101
+ self._operations_folder_name: dict[str, str] = {}
102
+ self._relative_import_path: dict[str, str] = {}
103
+ self.metadata: dict[str, Any] = yaml_data.get("metadata", {})
104
104
 
105
105
  @staticmethod
106
106
  def get_imported_namespace_for_client(imported_namespace: str, async_mode: bool = False) -> str:
@@ -160,7 +160,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
160
160
  return "_".join(parts) + (str(dot_num) if dot_num > 0 else "")
161
161
 
162
162
  @property
163
- def client_namespace_types(self) -> Dict[str, ClientNamespaceType]:
163
+ def client_namespace_types(self) -> dict[str, ClientNamespaceType]:
164
164
  if not self._client_namespace_types:
165
165
  # calculate client namespace types for each kind of client namespace
166
166
  for client in self.clients:
@@ -202,7 +202,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
202
202
  return any(client.has_etag for client in self.clients)
203
203
 
204
204
  @staticmethod
205
- def clients_has_operations(clients: List[Client]) -> bool:
205
+ def clients_has_operations(clients: list[Client]) -> bool:
206
206
  return any(c for c in clients if c.has_operations)
207
207
 
208
208
  @property
@@ -235,7 +235,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
235
235
  def client_filename(self) -> str:
236
236
  return self.clients[0].filename
237
237
 
238
- def get_clients(self, client_namespace: str) -> List[Client]:
238
+ def get_clients(self, client_namespace: str) -> list[Client]:
239
239
  """Get all clients in specific namespace"""
240
240
  return self.client_namespace_types.get(client_namespace, ClientNamespaceType()).clients
241
241
 
@@ -332,7 +332,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
332
332
  raise KeyError(f"Couldn't find schema with id {schema_id}") from exc
333
333
 
334
334
  @property
335
- def model_types(self) -> List[ModelType]:
335
+ def model_types(self) -> list[ModelType]:
336
336
  """All of the model types in this class"""
337
337
  if not self._model_types:
338
338
  self._model_types = [
@@ -341,19 +341,19 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
341
341
  return self._model_types
342
342
 
343
343
  @model_types.setter
344
- def model_types(self, val: List[ModelType]) -> None:
344
+ def model_types(self, val: list[ModelType]) -> None:
345
345
  self._model_types = val
346
346
 
347
347
  @staticmethod
348
- def get_public_model_types(models: List[ModelType]) -> List[ModelType]:
348
+ def get_public_model_types(models: list[ModelType]) -> list[ModelType]:
349
349
  return [m for m in models if not m.internal and not m.base == "json"]
350
350
 
351
351
  @property
352
- def public_model_types(self) -> List[ModelType]:
352
+ def public_model_types(self) -> list[ModelType]:
353
353
  return self.get_public_model_types(self.model_types)
354
354
 
355
355
  @property
356
- def enums(self) -> List[EnumType]:
356
+ def enums(self) -> list[EnumType]:
357
357
  """All of the enums"""
358
358
  return [t for t in self.types_map.values() if isinstance(t, EnumType)]
359
359
 
@@ -364,8 +364,8 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
364
364
  def _sort_model_types_helper(
365
365
  self,
366
366
  current: ModelType,
367
- seen_schema_names: Set[str],
368
- seen_schema_yaml_ids: Set[int],
367
+ seen_schema_names: set[str],
368
+ seen_schema_yaml_ids: set[int],
369
369
  ):
370
370
  if current.id in seen_schema_yaml_ids:
371
371
  return []
@@ -389,9 +389,9 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
389
389
  :return: None
390
390
  :rtype: None
391
391
  """
392
- seen_schema_names: Set[str] = set()
393
- seen_schema_yaml_ids: Set[int] = set()
394
- sorted_object_schemas: List[ModelType] = []
392
+ seen_schema_names: set[str] = set()
393
+ seen_schema_yaml_ids: set[int] = set()
394
+ sorted_object_schemas: list[ModelType] = []
395
395
  for schema in sorted(self.model_types, key=lambda x: x.name.lower()):
396
396
  sorted_object_schemas.extend(self._sort_model_types_helper(schema, seen_schema_names, seen_schema_yaml_ids))
397
397
  self.model_types = sorted_object_schemas
@@ -415,7 +415,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
415
415
  return _is_legacy(self.options)
416
416
 
417
417
  @staticmethod
418
- def has_non_json_models(models: List[ModelType]) -> bool:
418
+ def has_non_json_models(models: list[ModelType]) -> bool:
419
419
  return any(m for m in models if m.base != "json")
420
420
 
421
421
  @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, Dict, List, Optional, TYPE_CHECKING, Type, Tuple, Union
6
+ from typing import Any, Optional, TYPE_CHECKING, Type, Union
7
7
  import re
8
8
  from .imports import FileImport, ImportType, TypingSection
9
9
  from .base import BaseType
@@ -23,9 +23,9 @@ class CombinedType(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
- types: List[BaseType],
28
+ types: list[BaseType],
29
29
  ) -> None:
30
30
  super().__init__(yaml_data, code_model)
31
31
  self.types = types # the types that this type is combining
@@ -104,7 +104,7 @@ class CombinedType(BaseType):
104
104
  client_default_value_declaration=client_default_value_declaration,
105
105
  )
106
106
 
107
- def get_polymorphic_subtypes(self, polymorphic_subtypes: List["ModelType"]) -> None:
107
+ def get_polymorphic_subtypes(self, polymorphic_subtypes: list["ModelType"]) -> None:
108
108
  raise ValueError("You shouldn't get polymorphic subtypes of multiple types")
109
109
 
110
110
  @property
@@ -131,7 +131,7 @@ class CombinedType(BaseType):
131
131
  return file_import
132
132
 
133
133
  @classmethod
134
- def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "BaseType":
134
+ def from_yaml(cls, yaml_data: dict[str, Any], code_model: "CodeModel") -> "BaseType":
135
135
  from . import build_type
136
136
 
137
137
  return cls(
@@ -143,8 +143,8 @@ class CombinedType(BaseType):
143
143
  def target_model_subtype(
144
144
  self,
145
145
  target_types: Union[
146
- Tuple[Type[ModelType]],
147
- Tuple[Type[ModelType], Type[ModelType]],
146
+ tuple[Type[ModelType]],
147
+ tuple[Type[ModelType], Type[ModelType]],
148
148
  ],
149
149
  ) -> Optional[ModelType]:
150
150
  for sub_t in self.types:
@@ -4,7 +4,7 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  import logging
7
- from typing import Dict, Any, Optional, TYPE_CHECKING, Union
7
+ from typing import Any, Optional, TYPE_CHECKING, Union
8
8
  from .base import BaseType
9
9
  from .imports import FileImport, ImportType, TypingSection
10
10
  from .primitive_types import IntegerType, BinaryType, StringType, BooleanType
@@ -28,7 +28,7 @@ class ConstantType(BaseType):
28
28
 
29
29
  def __init__(
30
30
  self,
31
- yaml_data: Dict[str, Any],
31
+ yaml_data: dict[str, Any],
32
32
  code_model: "CodeModel",
33
33
  value_type: BaseType,
34
34
  value: Optional[Union[str, int, float]],
@@ -82,7 +82,7 @@ class ConstantType(BaseType):
82
82
  return isinstance(self.value_type, (IntegerType, BinaryType, StringType, BooleanType))
83
83
 
84
84
  @classmethod
85
- def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "ConstantType":
85
+ def from_yaml(cls, yaml_data: dict[str, Any], code_model: "CodeModel") -> "ConstantType":
86
86
  """Constructs a ConstantType from yaml data.
87
87
 
88
88
  :param yaml_data: the yaml data from which we will construct this schema
@@ -109,16 +109,9 @@ class ConstantType(BaseType):
109
109
  client_default_value_declaration=self.get_declaration(),
110
110
  )
111
111
 
112
- def _imports_shared(self, **kwargs: Any):
112
+ def imports(self, **kwargs: Any) -> FileImport:
113
113
  file_import = super().imports(**kwargs)
114
114
  file_import.merge(self.value_type.imports(**kwargs))
115
- return file_import
116
-
117
- def imports_for_multiapi(self, **kwargs: Any) -> FileImport:
118
- return self._imports_shared(**kwargs)
119
-
120
- def imports(self, **kwargs: Any) -> FileImport:
121
- file_import = self._imports_shared(**kwargs)
122
115
  if self._is_literal:
123
116
  file_import.add_submodule_import("typing", "Literal", ImportType.STDLIB, TypingSection.REGULAR)
124
117
  return file_import
@@ -7,9 +7,7 @@ from abc import abstractmethod
7
7
  from typing import (
8
8
  Optional,
9
9
  Any,
10
- Dict,
11
10
  TYPE_CHECKING,
12
- List,
13
11
  Generic,
14
12
  TypeVar,
15
13
  Union,
@@ -29,7 +27,7 @@ class _CredentialPolicyBaseType:
29
27
  Inherited by our BearerTokenCredentialPolicy and KeyCredentialPolicy types.
30
28
  """
31
29
 
32
- def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
30
+ def __init__(self, yaml_data: dict[str, Any], code_model: "CodeModel") -> None:
33
31
  self.yaml_data = yaml_data
34
32
  self.code_model = code_model
35
33
 
@@ -45,10 +43,10 @@ class BearerTokenCredentialPolicyType(_CredentialPolicyBaseType):
45
43
 
46
44
  def __init__(
47
45
  self,
48
- yaml_data: Dict[str, Any],
46
+ yaml_data: dict[str, Any],
49
47
  code_model: "CodeModel",
50
- credential_scopes: List[str],
51
- flows: Optional[Dict[str, Any]] = None,
48
+ credential_scopes: list[str],
49
+ flows: Optional[dict[str, Any]] = None,
52
50
  ) -> None:
53
51
  super().__init__(yaml_data, code_model)
54
52
  self.credential_scopes = credential_scopes
@@ -60,7 +58,7 @@ class BearerTokenCredentialPolicyType(_CredentialPolicyBaseType):
60
58
  return f"policies.{policy_name}(self.credential, *self.credential_scopes, {auth_flows}**kwargs)"
61
59
 
62
60
  @classmethod
63
- def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "BearerTokenCredentialPolicyType":
61
+ def from_yaml(cls, yaml_data: dict[str, Any], code_model: "CodeModel") -> "BearerTokenCredentialPolicyType":
64
62
  return cls(yaml_data, code_model, yaml_data["credentialScopes"], yaml_data.get("flows"))
65
63
 
66
64
 
@@ -75,7 +73,7 @@ class ARMChallengeAuthenticationPolicyType(BearerTokenCredentialPolicyType):
75
73
  class KeyCredentialPolicyType(_CredentialPolicyBaseType):
76
74
  def __init__(
77
75
  self,
78
- yaml_data: Dict[str, Any],
76
+ yaml_data: dict[str, Any],
79
77
  code_model: "CodeModel",
80
78
  key: str,
81
79
  scheme: Optional[str] = None,
@@ -95,7 +93,7 @@ class KeyCredentialPolicyType(_CredentialPolicyBaseType):
95
93
  return f"policies.{self.credential_name}Policy(self.credential, {params}**kwargs)"
96
94
 
97
95
  @classmethod
98
- def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "KeyCredentialPolicyType":
96
+ def from_yaml(cls, yaml_data: dict[str, Any], code_model: "CodeModel") -> "KeyCredentialPolicyType":
99
97
  return cls(yaml_data, code_model, yaml_data["key"], yaml_data.get("scheme", None))
100
98
 
101
99
 
@@ -114,7 +112,7 @@ class CredentialType(Generic[CredentialPolicyType], BaseType):
114
112
 
115
113
  def __init__(
116
114
  self,
117
- yaml_data: Dict[str, Any],
115
+ yaml_data: dict[str, Any],
118
116
  code_model: "CodeModel",
119
117
  policy: CredentialPolicyType,
120
118
  ) -> None:
@@ -138,7 +136,7 @@ class CredentialType(Generic[CredentialPolicyType], BaseType):
138
136
  return self.docstring_type()
139
137
 
140
138
  @classmethod
141
- def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "CredentialType":
139
+ def from_yaml(cls, yaml_data: dict[str, Any], code_model: "CodeModel") -> "CredentialType":
142
140
  from . import build_type
143
141
 
144
142
  return cls(
@@ -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