@autorest/python 5.16.0 → 5.19.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 (96) hide show
  1. package/ChangeLog.md +79 -4
  2. package/README.md +30 -4
  3. package/autorest/__init__.py +1 -1
  4. package/autorest/codegen/__init__.py +55 -211
  5. package/autorest/codegen/models/__init__.py +116 -83
  6. package/autorest/codegen/models/base_builder.py +49 -88
  7. package/autorest/codegen/models/base_model.py +1 -1
  8. package/autorest/codegen/models/{base_schema.py → base_type.py} +61 -39
  9. package/autorest/codegen/models/client.py +165 -53
  10. package/autorest/codegen/models/code_model.py +122 -257
  11. package/autorest/codegen/models/combined_type.py +107 -0
  12. package/autorest/codegen/models/{constant_schema.py → constant_type.py} +49 -40
  13. package/autorest/codegen/models/credential_types.py +224 -0
  14. package/autorest/codegen/models/dictionary_type.py +131 -0
  15. package/autorest/codegen/models/enum_type.py +195 -0
  16. package/autorest/codegen/models/imports.py +80 -2
  17. package/autorest/codegen/models/list_type.py +149 -0
  18. package/autorest/codegen/models/lro_operation.py +79 -156
  19. package/autorest/codegen/models/lro_paging_operation.py +28 -11
  20. package/autorest/codegen/models/model_type.py +262 -0
  21. package/autorest/codegen/models/operation.py +331 -298
  22. package/autorest/codegen/models/operation_group.py +54 -91
  23. package/autorest/codegen/models/paging_operation.py +82 -123
  24. package/autorest/codegen/models/parameter.py +289 -396
  25. package/autorest/codegen/models/parameter_list.py +355 -360
  26. package/autorest/codegen/models/primitive_types.py +544 -0
  27. package/autorest/codegen/models/property.py +123 -139
  28. package/autorest/codegen/models/request_builder.py +130 -102
  29. package/autorest/codegen/models/request_builder_parameter.py +112 -100
  30. package/autorest/codegen/models/response.py +325 -0
  31. package/autorest/codegen/models/utils.py +12 -19
  32. package/autorest/codegen/serializers/__init__.py +55 -37
  33. package/autorest/codegen/serializers/builder_serializer.py +695 -1144
  34. package/autorest/codegen/serializers/client_serializer.py +92 -89
  35. package/autorest/codegen/serializers/general_serializer.py +15 -69
  36. package/autorest/codegen/serializers/import_serializer.py +7 -4
  37. package/autorest/codegen/serializers/metadata_serializer.py +15 -104
  38. package/autorest/codegen/serializers/model_base_serializer.py +49 -36
  39. package/autorest/codegen/serializers/model_generic_serializer.py +8 -6
  40. package/autorest/codegen/serializers/model_init_serializer.py +2 -4
  41. package/autorest/codegen/serializers/model_python3_serializer.py +22 -16
  42. package/autorest/codegen/serializers/operation_groups_serializer.py +7 -13
  43. package/autorest/codegen/serializers/parameter_serializer.py +174 -0
  44. package/autorest/codegen/serializers/request_builders_serializer.py +13 -30
  45. package/autorest/codegen/serializers/utils.py +0 -140
  46. package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
  47. package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +10 -7
  48. package/autorest/codegen/templates/config.py.jinja2 +13 -13
  49. package/autorest/codegen/templates/enum.py.jinja2 +4 -4
  50. package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
  51. package/autorest/codegen/templates/init.py.jinja2 +2 -2
  52. package/autorest/codegen/templates/lro_operation.py.jinja2 +4 -1
  53. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +4 -1
  54. package/autorest/codegen/templates/metadata.json.jinja2 +33 -33
  55. package/autorest/codegen/templates/model.py.jinja2 +23 -24
  56. package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
  57. package/autorest/codegen/templates/model_init.py.jinja2 +3 -5
  58. package/autorest/codegen/templates/operation.py.jinja2 +6 -8
  59. package/autorest/codegen/templates/operation_group.py.jinja2 +21 -8
  60. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +2 -2
  61. package/autorest/codegen/templates/operation_tools.jinja2 +11 -3
  62. package/autorest/codegen/templates/paging_operation.py.jinja2 +2 -2
  63. package/autorest/codegen/templates/request_builder.py.jinja2 +10 -15
  64. package/autorest/codegen/templates/request_builders.py.jinja2 +1 -1
  65. package/autorest/codegen/templates/serialization.py.jinja2 +2006 -0
  66. package/autorest/codegen/templates/setup.py.jinja2 +13 -3
  67. package/autorest/codegen/templates/vendor.py.jinja2 +11 -1
  68. package/autorest/jsonrpc/server.py +15 -3
  69. package/autorest/m4reformatter/__init__.py +1126 -0
  70. package/autorest/multiapi/models/client.py +12 -2
  71. package/autorest/multiapi/models/code_model.py +1 -1
  72. package/autorest/multiapi/serializers/__init__.py +18 -4
  73. package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
  74. package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
  75. package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +4 -4
  76. package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
  77. package/autorest/postprocess/__init__.py +202 -0
  78. package/autorest/postprocess/get_all.py +19 -0
  79. package/autorest/postprocess/venvtools.py +73 -0
  80. package/autorest/preprocess/__init__.py +210 -0
  81. package/autorest/preprocess/helpers.py +54 -0
  82. package/autorest/{namer → preprocess}/python_mappings.py +21 -16
  83. package/package.json +2 -2
  84. package/autorest/codegen/models/credential_model.py +0 -55
  85. package/autorest/codegen/models/credential_schema.py +0 -95
  86. package/autorest/codegen/models/credential_schema_policy.py +0 -73
  87. package/autorest/codegen/models/dictionary_schema.py +0 -106
  88. package/autorest/codegen/models/enum_schema.py +0 -225
  89. package/autorest/codegen/models/list_schema.py +0 -135
  90. package/autorest/codegen/models/object_schema.py +0 -303
  91. package/autorest/codegen/models/primitive_schemas.py +0 -495
  92. package/autorest/codegen/models/request_builder_parameter_list.py +0 -249
  93. package/autorest/codegen/models/schema_request.py +0 -55
  94. package/autorest/codegen/models/schema_response.py +0 -141
  95. package/autorest/namer/__init__.py +0 -23
  96. package/autorest/namer/name_converter.py +0 -509
@@ -3,133 +3,145 @@
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
6
+ from typing import TYPE_CHECKING, Any, Dict, Union
7
7
  from .parameter import (
8
- ParameterMethodLocation,
9
- ParameterOnlyPathAndBodyPositional,
10
8
  ParameterLocation,
11
- ParameterStyle,
12
- get_target_property_name,
9
+ ParameterMethodLocation,
10
+ Parameter,
11
+ BodyParameter,
12
+ _MultipartBodyParameter,
13
13
  )
14
- from .utils import get_schema
14
+ from .base_type import BaseType
15
+ from .primitive_types import BinaryType, StringType
16
+ from .combined_type import CombinedType
15
17
 
16
18
  if TYPE_CHECKING:
17
19
  from .code_model import CodeModel
18
20
 
19
21
 
20
- def _make_public(name):
21
- if name[0] == "_":
22
- return name[1:]
23
- return name
22
+ class RequestBuilderBodyParameter(BodyParameter):
23
+ """BOdy parmaeter for RequestBuilders"""
24
24
 
25
+ def __init__(self, *args, **kwargs) -> None:
26
+ super().__init__(*args, **kwargs)
27
+ if isinstance(self.type, (BinaryType, StringType)) or any(
28
+ "xml" in ct for ct in self.content_types
29
+ ):
30
+ self.client_name = "content"
31
+ else:
32
+ self.client_name = "json"
33
+
34
+ def type_annotation(self, **kwargs: Any) -> str:
35
+ if self.type.is_xml:
36
+ return "Any" # xml type technically not in type signature for HttpRequest content param
37
+ return super().type_annotation(**kwargs)
25
38
 
26
- class RequestBuilderParameter(ParameterOnlyPathAndBodyPositional):
27
39
  @property
28
40
  def in_method_signature(self) -> bool:
29
- return not (
30
- # if not inputtable, don't put in signature
31
- not self.inputtable_by_user
32
- # If i'm not in the method code, no point in being in signature
33
- or not self.in_method_code
34
- # If I'm a flattened property of a body, don't want me, want the body param
35
- or self.target_property_name
36
- or not self.in_method_code
41
+ return super().in_method_signature and not self.is_partial_body
42
+
43
+ @property
44
+ def method_location(self) -> ParameterMethodLocation:
45
+ return (
46
+ ParameterMethodLocation.KWARG
47
+ if (self.constant or isinstance(self.type, CombinedType))
48
+ else ParameterMethodLocation.KEYWORD_ONLY
37
49
  )
38
50
 
51
+ @classmethod
52
+ def from_yaml(
53
+ cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
54
+ ) -> "RequestBuilderBodyParameter":
55
+ return super().from_yaml(yaml_data, code_model) # type: ignore
56
+
39
57
  @property
40
58
  def name_in_high_level_operation(self) -> str:
41
- if self.is_body and not self.constant:
42
- return f"_{self.serialized_name}"
43
- name = self.yaml_data["language"]["python"]["name"]
44
- if self.implementation == "Client" and self.in_method_code:
45
- # for these, we're passing the client params to the request builder.
46
- # Need the self._config prefix
47
- name = f"self._config.{name}"
48
- return name
59
+ if self.client_name == "json":
60
+ return "_json"
61
+ return "_content"
62
+
63
+
64
+ class RequestBuilderMultipartBodyParameter(
65
+ _MultipartBodyParameter[ # pylint: disable=unsubscriptable-object
66
+ RequestBuilderBodyParameter
67
+ ]
68
+ ):
69
+ """Multipart body parameter for Request BUilders"""
70
+
71
+ @property
72
+ def name_in_high_level_operation(self) -> str:
73
+ return f"_{self.client_name}"
74
+
75
+ @classmethod
76
+ def from_yaml(
77
+ cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
78
+ ) -> "RequestBuilderMultipartBodyParameter":
79
+ return cls(
80
+ yaml_data=yaml_data,
81
+ code_model=code_model,
82
+ type=code_model.lookup_type(id(yaml_data["type"])),
83
+ entries=[
84
+ RequestBuilderBodyParameter.from_yaml(entry, code_model)
85
+ for entry in yaml_data["entries"]
86
+ ],
87
+ )
88
+
89
+
90
+ class RequestBuilderParameter(Parameter):
91
+ """Basic RequestBuilder Parameter."""
92
+
93
+ def __init__(
94
+ self, yaml_data: Dict[str, Any], code_model: "CodeModel", type: BaseType
95
+ ) -> None:
96
+ super().__init__(yaml_data, code_model, type)
97
+ # we don't want any default content type behavior in request builder
98
+ if self.rest_api_name == "Content-Type":
99
+ self.client_default_value = None
100
+ if self.grouped_by and self.client_name[0] == "_":
101
+ # we don't want hidden parameters for grouped by in request builders
102
+ self.client_name = self.client_name[1:]
49
103
 
50
104
  @property
51
- def in_method_code(self) -> bool:
52
- if self.location == ParameterLocation.Uri:
53
- # don't want any base url path formatting arguments
54
- return False
55
- return super(RequestBuilderParameter, self).in_method_code
105
+ def in_method_signature(self) -> bool:
106
+ if self.grouped_by and not self.in_flattened_body:
107
+ return True
108
+ return super().in_method_signature and not (
109
+ self.location == ParameterLocation.ENDPOINT_PATH
110
+ or self.in_flattened_body
111
+ or self.grouper
112
+ )
56
113
 
57
114
  @property
58
- def default_value_declaration(self) -> Optional[str]:
59
- if self.serialized_name == "content_type":
60
- # in request builders we're in a weird scenario
61
- # we need to know what the types of content_type are
62
- # but we want to serialize content_type with no default.
63
- # So, we just return None in default_value_declaration for now
64
- return "None"
65
- return super().default_value_declaration
115
+ def full_client_name(self) -> str:
116
+ return self.client_name
66
117
 
67
118
  @property
68
119
  def method_location(self) -> ParameterMethodLocation:
69
120
  super_method_location = super().method_location
70
- if super_method_location in (
71
- ParameterMethodLocation.KWARG,
72
- ParameterMethodLocation.HIDDEN_KWARG,
73
- ):
121
+ if super_method_location == ParameterMethodLocation.KWARG:
74
122
  return super_method_location
75
- if self.location != ParameterLocation.Path:
123
+ if (
124
+ self.in_overriden
125
+ and super_method_location == ParameterMethodLocation.KEYWORD_ONLY
126
+ ):
127
+ return ParameterMethodLocation.KWARG
128
+ if self.location != ParameterLocation.PATH:
76
129
  return ParameterMethodLocation.KEYWORD_ONLY
77
130
  return super_method_location
78
131
 
79
- @method_location.setter
80
- def method_location(self, val: ParameterMethodLocation) -> None:
81
- self._method_location = val
82
-
83
132
  @property
84
- def full_serialized_name(self) -> str:
85
- return self.serialized_name
133
+ def name_in_high_level_operation(self) -> str:
134
+ if self.grouped_by:
135
+ return f"_{self.client_name}"
136
+ if self.implementation == "Client":
137
+ return f"self._config.{self.client_name}"
138
+ return self.client_name
86
139
 
87
- @classmethod
88
- def from_yaml(
89
- cls,
90
- yaml_data: Dict[str, Any],
91
- code_model: "CodeModel",
92
- *,
93
- content_types: Optional[List[str]] = None,
94
- ) -> "RequestBuilderParameter":
95
- http_protocol = yaml_data["protocol"].get(
96
- "http", {"in": ParameterLocation.Other}
97
- )
98
- name = yaml_data["language"]["python"]["name"]
99
- location = ParameterLocation(http_protocol["in"])
100
- serialized_name = yaml_data["language"]["python"]["name"]
101
- schema = get_schema(code_model, yaml_data.get("schema"), serialized_name)
102
- target_property = yaml_data.get("targetProperty")
103
- target_property_name = (
104
- get_target_property_name(code_model, id(target_property))
105
- if target_property
106
- else None
107
- )
108
- return cls(
109
- code_model=code_model,
110
- yaml_data=yaml_data,
111
- schema=schema,
112
- # See also https://github.com/Azure/autorest.modelerfour/issues/80
113
- rest_api_name=yaml_data["language"]["default"].get(
114
- "serializedName", yaml_data["language"]["default"]["name"]
115
- ),
116
- serialized_name=_make_public(name),
117
- description=yaml_data["language"]["python"]["description"],
118
- implementation=yaml_data["implementation"],
119
- required=yaml_data.get("required", False),
120
- location=location,
121
- skip_url_encoding=yaml_data.get("extensions", {}).get(
122
- "x-ms-skip-url-encoding", False
123
- ),
124
- constraints=[], # FIXME constraints
125
- target_property_name=target_property_name,
126
- style=ParameterStyle(http_protocol["style"])
127
- if "style" in http_protocol
128
- else None,
129
- explode=http_protocol.get("explode", False),
130
- grouped_by=yaml_data.get("groupedBy", None),
131
- original_parameter=yaml_data.get("originalParameter", None),
132
- flattened=yaml_data.get("flattened", False),
133
- client_default_value=yaml_data.get("clientDefaultValue"),
134
- content_types=content_types,
135
- )
140
+
141
+ def get_request_body_parameter(
142
+ yaml_data: Dict[str, Any], code_model: "CodeModel"
143
+ ) -> Union[RequestBuilderBodyParameter, RequestBuilderMultipartBodyParameter]:
144
+ """Get body parameter for a request builder"""
145
+ if yaml_data.get("entries"):
146
+ return RequestBuilderMultipartBodyParameter.from_yaml(yaml_data, code_model)
147
+ return RequestBuilderBodyParameter.from_yaml(yaml_data, code_model)
@@ -0,0 +1,325 @@
1
+ # -------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # Licensed under the MIT License. See License.txt in the project root for
4
+ # license information.
5
+ # --------------------------------------------------------------------------
6
+ from typing import Dict, Optional, List, Any, TYPE_CHECKING, Union
7
+
8
+ from .base_model import BaseModel
9
+ from .base_type import BaseType
10
+ from .imports import FileImport, ImportType
11
+ from .primitive_types import BinaryType, BinaryIteratorType
12
+ from .dictionary_type import DictionaryType
13
+ from .list_type import ListType
14
+ from .model_type import ModelType
15
+
16
+ if TYPE_CHECKING:
17
+ from .code_model import CodeModel
18
+
19
+
20
+ class ResponseHeader(BaseModel):
21
+ def __init__(
22
+ self, yaml_data: Dict[str, Any], code_model: "CodeModel", type: BaseType
23
+ ) -> None:
24
+ super().__init__(yaml_data, code_model)
25
+ self.rest_api_name: str = yaml_data["restApiName"]
26
+ self.type = type
27
+
28
+ @property
29
+ def serialization_type(self) -> str:
30
+ return self.type.serialization_type
31
+
32
+ @classmethod
33
+ def from_yaml(
34
+ cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
35
+ ) -> "ResponseHeader":
36
+ return cls(
37
+ yaml_data=yaml_data,
38
+ code_model=code_model,
39
+ type=code_model.lookup_type(id(yaml_data["type"])),
40
+ )
41
+
42
+
43
+ class Response(BaseModel):
44
+ def __init__(
45
+ self,
46
+ yaml_data: Dict[str, Any],
47
+ code_model: "CodeModel",
48
+ *,
49
+ headers: List[ResponseHeader] = [],
50
+ type: Optional[BaseType] = None,
51
+ ) -> None:
52
+ super().__init__(yaml_data=yaml_data, code_model=code_model)
53
+ self.status_codes: List[Union[int, str]] = yaml_data["statusCodes"]
54
+ self.headers = headers
55
+ self.type = type
56
+ self.nullable = yaml_data.get("nullable")
57
+
58
+ def get_json_template_representation(self) -> Any:
59
+ if not self.type:
60
+ return None
61
+ if not isinstance(self.type, (DictionaryType, ListType, ModelType)):
62
+ return None
63
+ return self.type.get_json_template_representation()
64
+
65
+ @property
66
+ def is_stream_response(self) -> bool:
67
+ """Is the response expected to be streamable, like a download."""
68
+ return isinstance(self.type, BinaryIteratorType)
69
+
70
+ @property
71
+ def serialization_type(self) -> str:
72
+ if self.type:
73
+ return self.type.serialization_type
74
+ return "None"
75
+
76
+ def type_annotation(self, **kwargs: Any) -> str:
77
+ if self.type:
78
+ kwargs["is_operation_file"] = True
79
+ type_annot = self.type.type_annotation(**kwargs)
80
+ if self.nullable:
81
+ return f"Optional[{type_annot}]"
82
+ return type_annot
83
+ return "None"
84
+
85
+ def docstring_text(self, **kwargs: Any) -> str:
86
+ if self.nullable and self.type:
87
+ return f"{self.type.docstring_text(**kwargs)} or None"
88
+ return self.type.docstring_text(**kwargs) if self.type else "None"
89
+
90
+ def docstring_type(self, **kwargs: Any) -> str:
91
+ if self.nullable and self.type:
92
+ return f"{self.type.docstring_type(**kwargs)} or None"
93
+ return self.type.docstring_type(**kwargs) if self.type else "None"
94
+
95
+ def _imports_shared(self, **kwargs: Any) -> FileImport:
96
+ file_import = FileImport()
97
+ if self.type:
98
+ file_import.merge(self.type.imports(is_operation_file=True, **kwargs))
99
+ if self.nullable:
100
+ file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
101
+ return file_import
102
+
103
+ def imports(self, **kwargs: Any) -> FileImport:
104
+ return self._imports_shared(**kwargs)
105
+
106
+ def imports_for_multiapi(self, **kwargs: Any) -> FileImport:
107
+ return self._imports_shared(**kwargs)
108
+
109
+ @classmethod
110
+ def from_yaml(
111
+ cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
112
+ ) -> "Response":
113
+ type = (
114
+ code_model.lookup_type(id(yaml_data["type"]))
115
+ if yaml_data.get("type")
116
+ else None
117
+ )
118
+ # use ByteIteratorType if we are returning a binary type
119
+ if isinstance(type, BinaryType):
120
+ type = BinaryIteratorType(type.yaml_data, type.code_model)
121
+ return cls(
122
+ yaml_data=yaml_data,
123
+ code_model=code_model,
124
+ headers=[
125
+ ResponseHeader.from_yaml(header, code_model)
126
+ for header in yaml_data["headers"]
127
+ ],
128
+ type=type,
129
+ )
130
+
131
+ def __repr__(self) -> str:
132
+ return f"<{self.__class__.__name__} {self.status_codes}>"
133
+
134
+
135
+ class PagingResponse(Response):
136
+ def __init__(self, *args, **kwargs) -> None:
137
+ super().__init__(*args, **kwargs)
138
+ self.item_type = self.code_model.lookup_type(id(self.yaml_data["itemType"]))
139
+
140
+ def get_json_template_representation(self) -> Any:
141
+ return self.item_type.get_json_template_representation()
142
+
143
+ def get_pager_path(self, async_mode: bool) -> str:
144
+ return (
145
+ self.yaml_data["pagerAsync"] if async_mode else self.yaml_data["pagerSync"]
146
+ )
147
+
148
+ def get_pager(self, async_mode: bool) -> str:
149
+ return self.get_pager_path(async_mode).split(".")[-1]
150
+
151
+ def type_annotation(self, **kwargs: Any) -> str:
152
+ iterable = "AsyncIterable" if kwargs["async_mode"] else "Iterable"
153
+ return f"{iterable}[{self.item_type.type_annotation(**kwargs)}]"
154
+
155
+ def docstring_text(self, **kwargs: Any) -> str:
156
+ base_description = "An iterator like instance of "
157
+ if not self.code_model.options["version_tolerant"]:
158
+ base_description += "either "
159
+ return base_description + self.item_type.docstring_text(**kwargs)
160
+
161
+ def docstring_type(self, **kwargs: Any) -> str:
162
+ return f"~{self.get_pager_path(kwargs['async_mode'])}[{self.item_type.docstring_type(**kwargs)}]"
163
+
164
+ def _imports_shared(self, **kwargs: Any) -> FileImport:
165
+ file_import = super()._imports_shared(**kwargs)
166
+ async_mode = kwargs.pop("async_mode")
167
+ pager_import_path = ".".join(self.get_pager_path(async_mode).split(".")[:-1])
168
+ pager = self.get_pager(async_mode)
169
+
170
+ file_import.add_submodule_import(pager_import_path, pager, ImportType.AZURECORE)
171
+ return file_import
172
+
173
+ def imports(self, **kwargs: Any) -> FileImport:
174
+ file_import = self._imports_shared(**kwargs)
175
+ async_mode = kwargs.pop("async_mode")
176
+ if async_mode:
177
+ file_import.add_submodule_import(
178
+ "azure.core.async_paging", "AsyncList", ImportType.AZURECORE
179
+ )
180
+
181
+ return file_import
182
+
183
+ def imports_for_multiapi(self, **kwargs: Any) -> FileImport:
184
+ return self._imports_shared(**kwargs)
185
+
186
+
187
+ class LROResponse(Response):
188
+ def get_poller_path(self, async_mode: bool) -> str:
189
+ return (
190
+ self.yaml_data["pollerAsync"]
191
+ if async_mode
192
+ else self.yaml_data["pollerSync"]
193
+ )
194
+
195
+ def get_poller(self, async_mode: bool) -> str:
196
+ """Get the name of the poller. Default is LROPoller / AsyncLROPoller"""
197
+ return self.get_poller_path(async_mode).split(".")[-1]
198
+
199
+ def get_polling_method_path(self, async_mode: bool) -> str:
200
+ """Get the full name of the poller path. Default are the azure core pollers"""
201
+ return (
202
+ self.yaml_data["pollingMethodAsync"]
203
+ if async_mode
204
+ else self.yaml_data["pollingMethodSync"]
205
+ )
206
+
207
+ def get_polling_method(self, async_mode: bool) -> str:
208
+ """Get the default pollint method"""
209
+ return self.get_polling_method_path(async_mode).split(".")[-1]
210
+
211
+ @staticmethod
212
+ def get_no_polling_method_path(async_mode: bool) -> str:
213
+ """Get the path of the default of no polling method"""
214
+ return f"azure.core.polling.{'Async' if async_mode else ''}NoPolling"
215
+
216
+ def get_no_polling_method(self, async_mode: bool) -> str:
217
+ """Get the default no polling method"""
218
+ return self.get_no_polling_method_path(async_mode).split(".")[-1]
219
+
220
+ @staticmethod
221
+ def get_base_polling_method_path(async_mode: bool) -> str:
222
+ """Get the base polling method path. Used in docstrings and type annotations."""
223
+ return f"azure.core.polling.{'Async' if async_mode else ''}PollingMethod"
224
+
225
+ def get_base_polling_method(self, async_mode: bool) -> str:
226
+ """Get the base polling method."""
227
+ return self.get_base_polling_method_path(async_mode).split(".")[-1]
228
+
229
+ def type_annotation(self, **kwargs: Any) -> str:
230
+ return f"{self.get_poller(kwargs.pop('async_mode'))}[{super().type_annotation(**kwargs)}]"
231
+
232
+ def docstring_type(self, **kwargs: Any) -> str:
233
+ return f"~{self.get_poller_path(kwargs.pop('async_mode'))}[{super().docstring_type(**kwargs)}]"
234
+
235
+ def docstring_text(self, **kwargs) -> str:
236
+ super_text = super().docstring_text(**kwargs)
237
+ base_description = (
238
+ f"An instance of {self.get_poller(kwargs.pop('async_mode'))} that returns "
239
+ )
240
+ if not self.code_model.options["version_tolerant"]:
241
+ base_description += "either "
242
+ return base_description + super_text
243
+
244
+ def _imports_shared(self, **kwargs: Any) -> FileImport:
245
+ file_import = super()._imports_shared(**kwargs)
246
+ async_mode = kwargs["async_mode"]
247
+ poller_import_path = ".".join(self.get_poller_path(async_mode).split(".")[:-1])
248
+ poller = self.get_poller(async_mode)
249
+ file_import.add_submodule_import(
250
+ poller_import_path, poller, ImportType.AZURECORE
251
+ )
252
+ return file_import
253
+
254
+ def imports(self, **kwargs: Any) -> FileImport:
255
+ file_import = self._imports_shared(**kwargs)
256
+ async_mode = kwargs["async_mode"]
257
+
258
+ default_polling_method_import_path = ".".join(
259
+ self.get_polling_method_path(async_mode).split(".")[:-1]
260
+ )
261
+ default_polling_method = self.get_polling_method(async_mode)
262
+ file_import.add_submodule_import(
263
+ default_polling_method_import_path,
264
+ default_polling_method,
265
+ ImportType.AZURECORE,
266
+ )
267
+ default_no_polling_method_import_path = ".".join(
268
+ self.get_no_polling_method_path(async_mode).split(".")[:-1]
269
+ )
270
+ default_no_polling_method = self.get_no_polling_method(async_mode)
271
+ file_import.add_submodule_import(
272
+ default_no_polling_method_import_path,
273
+ default_no_polling_method,
274
+ ImportType.AZURECORE,
275
+ )
276
+
277
+ base_polling_method_import_path = ".".join(
278
+ self.get_base_polling_method_path(async_mode).split(".")[:-1]
279
+ )
280
+ base_polling_method = self.get_base_polling_method(async_mode)
281
+ file_import.add_submodule_import(
282
+ base_polling_method_import_path, base_polling_method, ImportType.AZURECORE
283
+ )
284
+ return file_import
285
+
286
+ def imports_for_multiapi(self, **kwargs: Any) -> FileImport:
287
+ return self._imports_shared(**kwargs)
288
+
289
+
290
+ class LROPagingResponse(LROResponse, PagingResponse):
291
+ def type_annotation(self, **kwargs: Any) -> str:
292
+ paging_type_annotation = PagingResponse.type_annotation(self, **kwargs)
293
+ return f"{self.get_poller(kwargs.pop('async_mode'))}[{paging_type_annotation}]"
294
+
295
+ def docstring_type(self, **kwargs: Any) -> str:
296
+ paging_docstring_type = PagingResponse.docstring_type(self, **kwargs)
297
+ return f"~{self.get_poller_path(kwargs.pop('async_mode'))}[{paging_docstring_type}]"
298
+
299
+ def docstring_text(self, **kwargs) -> str:
300
+ base_description = (
301
+ "An instance of LROPoller that returns an iterator like instance of "
302
+ )
303
+ if not self.code_model.options["version_tolerant"]:
304
+ base_description += "either "
305
+ return base_description + Response.docstring_text(self)
306
+
307
+ def imports_for_multiapi(self, **kwargs: Any) -> FileImport:
308
+ file_import = LROResponse.imports_for_multiapi(self, **kwargs)
309
+ file_import.merge(PagingResponse.imports_for_multiapi(self, **kwargs))
310
+ return file_import
311
+
312
+ def imports(self, **kwargs: Any) -> FileImport:
313
+ file_import = LROResponse.imports(self, **kwargs)
314
+ file_import.merge(PagingResponse.imports(self, **kwargs))
315
+ return file_import
316
+
317
+
318
+ def get_response(yaml_data: Dict[str, Any], code_model: "CodeModel") -> Response:
319
+ if yaml_data["discriminator"] == "lropaging":
320
+ return LROPagingResponse.from_yaml(yaml_data, code_model)
321
+ if yaml_data["discriminator"] == "lro":
322
+ return LROResponse.from_yaml(yaml_data, code_model)
323
+ if yaml_data["discriminator"] == "paging":
324
+ return PagingResponse.from_yaml(yaml_data, code_model)
325
+ return Response.from_yaml(yaml_data, code_model)
@@ -4,28 +4,21 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  import re
7
- from typing import Any, TYPE_CHECKING
8
- import logging
9
- from .base_schema import BaseSchema
7
+ from typing import TypeVar, Dict
10
8
 
11
- if TYPE_CHECKING:
12
- from .code_model import CodeModel
9
+ JSON_REGEXP = re.compile(r"^(application|text)/(.+\+)?json$")
13
10
 
11
+ T = TypeVar("T")
12
+ OrderedSet = Dict[T, None]
14
13
 
15
- _LOGGER = logging.getLogger(__name__)
16
14
 
17
- JSON_REGEXP = re.compile(r"^(application|text)/(.+\+)?json$")
15
+ def add_to_description(description: str, entry: str) -> str:
16
+ if description:
17
+ return f"{description} {entry}"
18
+ return entry
18
19
 
19
20
 
20
- def get_schema(
21
- code_model: "CodeModel", schema: Any, serialized_name: str = "unknown"
22
- ) -> BaseSchema:
23
- if not isinstance(schema, dict):
24
- return schema
25
- schema_id = id(schema)
26
- _LOGGER.debug("Looking for id %s for member %s", schema_id, serialized_name)
27
- try:
28
- return code_model.lookup_schema(schema_id)
29
- except KeyError:
30
- _LOGGER.critical("Unable to ref the object")
31
- raise
21
+ def add_to_pylint_disable(curr_str: str, entry: str) -> str:
22
+ if curr_str:
23
+ return f"{curr_str},{entry}"
24
+ return f" # pylint: disable={entry}"