@autorest/python 6.1.4 → 6.1.5

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.
package/ChangeLog.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Release History
2
2
 
3
+ ### 2022-09-06 - 6.1.5
4
+
5
+ | Library | Min Version |
6
+ | ----------------------------------------------------------------------- | ----------- |
7
+ | `@autorest/core` | `3.8.4` |
8
+ | `@autorest/modelerfour` | `4.23.5` |
9
+ | `azure-core` dep of generated code | `1.24.0` |
10
+ | `isodate` dep of generated code | `0.6.1` |
11
+ | `msrest` dep of generated code (If generating legacy code) | `0.7.1` |
12
+ | `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.2` |
13
+
14
+ **Bug Fixes**
15
+
16
+ - Fix `api_version` error when there are multi different `api-version`(not multiapi) #1429
17
+ - Fix generator raising `KeyError` in corner case when generating an LRO-paging operation #1425
18
+
19
+ **Other Changes**
20
+
21
+ - Default `304` errors to throw `azure.core.exception.ResourceNotFoundError`s #1415
22
+
3
23
  ### 2022-08-31 - 6.1.4
4
24
 
5
25
  | Library | Min Version |
@@ -159,18 +159,18 @@ class TokenCredentialType(
159
159
  """Type of a token credential. Used by BearerAuth and ARMChallenge policies"""
160
160
 
161
161
  def type_annotation(self, **kwargs: Any) -> str: # pylint: disable=no-self-use
162
- if kwargs.pop("async_mode"):
162
+ if kwargs.get("async_mode"):
163
163
  return '"AsyncTokenCredential"'
164
164
  return '"TokenCredential"'
165
165
 
166
166
  def docstring_type(self, **kwargs: Any) -> str: # pylint: disable=no-self-use
167
- if kwargs.pop("async_mode"):
167
+ if kwargs.get("async_mode"):
168
168
  return "~azure.core.credentials_async.AsyncTokenCredential"
169
169
  return "~azure.core.credentials.TokenCredential"
170
170
 
171
171
  def imports(self, **kwargs: Any) -> FileImport: # pylint: disable=no-self-use
172
172
  file_import = FileImport()
173
- if kwargs.pop("async_mode"):
173
+ if kwargs.get("async_mode"):
174
174
  file_import.add_submodule_import(
175
175
  "azure.core.credentials_async",
176
176
  "AsyncTokenCredential",
@@ -291,27 +291,22 @@ class OperationBase( # pylint: disable=too-many-public-methods
291
291
  file_import.merge(self.parameters.body_parameter.type.imports(**kwargs))
292
292
 
293
293
  # Exceptions
294
- file_import.add_submodule_import(
295
- "azure.core.exceptions", "map_error", ImportType.AZURECORE
296
- )
294
+ errors = [
295
+ "map_error",
296
+ "HttpResponseError",
297
+ "ClientAuthenticationError",
298
+ "ResourceNotFoundError",
299
+ "ResourceExistsError",
300
+ "ResourceNotModifiedError",
301
+ ]
302
+ for error in errors:
303
+ file_import.add_submodule_import(
304
+ "azure.core.exceptions", error, ImportType.AZURECORE
305
+ )
297
306
  if self.code_model.options["azure_arm"]:
298
307
  file_import.add_submodule_import(
299
308
  "azure.mgmt.core.exceptions", "ARMErrorFormat", ImportType.AZURECORE
300
309
  )
301
- file_import.add_submodule_import(
302
- "azure.core.exceptions", "HttpResponseError", ImportType.AZURECORE
303
- )
304
- file_import.add_submodule_import(
305
- "azure.core.exceptions",
306
- "ClientAuthenticationError",
307
- ImportType.AZURECORE,
308
- )
309
- file_import.add_submodule_import(
310
- "azure.core.exceptions", "ResourceNotFoundError", ImportType.AZURECORE
311
- )
312
- file_import.add_submodule_import(
313
- "azure.core.exceptions", "ResourceExistsError", ImportType.AZURECORE
314
- )
315
310
 
316
311
  if self.has_kwargs_to_pop_with_default(
317
312
  self.parameters.kwargs_to_pop, ParameterLocation.HEADER
@@ -122,13 +122,13 @@ class BinaryIteratorType(PrimitiveType):
122
122
  return "IO"
123
123
 
124
124
  def docstring_type(self, **kwargs: Any) -> str:
125
- return "AsyncIterator[bytes]" if kwargs.pop("async_mode") else "Iterator[bytes]"
125
+ return "AsyncIterator[bytes]" if kwargs.get("async_mode") else "Iterator[bytes]"
126
126
 
127
127
  def type_annotation(self, **kwargs: Any) -> str:
128
128
  return self.docstring_type(**kwargs)
129
129
 
130
130
  def docstring_text(self, **kwargs: Any) -> str:
131
- iterator = "Async iterator" if kwargs.pop("async_mode") else "Iterator"
131
+ iterator = "Async iterator" if kwargs.get("async_mode") else "Iterator"
132
132
  return f"{iterator} of the response bytes"
133
133
 
134
134
  @property
@@ -137,7 +137,7 @@ class BinaryIteratorType(PrimitiveType):
137
137
 
138
138
  def imports(self, **kwargs: Any) -> FileImport:
139
139
  file_import = FileImport()
140
- iterator = "AsyncIterator" if kwargs.pop("async_mode") else "Iterator"
140
+ iterator = "AsyncIterator" if kwargs.get("async_mode") else "Iterator"
141
141
  file_import.add_submodule_import("typing", iterator, ImportType.STDLIB)
142
142
  return file_import
143
143
 
@@ -170,7 +170,7 @@ class PagingResponse(Response):
170
170
 
171
171
  def _imports_shared(self, **kwargs: Any) -> FileImport:
172
172
  file_import = super()._imports_shared(**kwargs)
173
- async_mode = kwargs.pop("async_mode")
173
+ async_mode = kwargs.get("async_mode", False)
174
174
  pager_import_path = ".".join(self.get_pager_path(async_mode).split(".")[:-1])
175
175
  pager = self.get_pager(async_mode)
176
176
 
@@ -179,7 +179,7 @@ class PagingResponse(Response):
179
179
 
180
180
  def imports(self, **kwargs: Any) -> FileImport:
181
181
  file_import = self._imports_shared(**kwargs)
182
- async_mode = kwargs.pop("async_mode")
182
+ async_mode = kwargs.get("async_mode")
183
183
  if async_mode:
184
184
  file_import.add_submodule_import(
185
185
  "azure.core.async_paging", "AsyncList", ImportType.AZURECORE
@@ -234,16 +234,14 @@ class LROResponse(Response):
234
234
  return self.get_base_polling_method_path(async_mode).split(".")[-1]
235
235
 
236
236
  def type_annotation(self, **kwargs: Any) -> str:
237
- return f"{self.get_poller(kwargs.pop('async_mode'))}[{super().type_annotation(**kwargs)}]"
237
+ return f"{self.get_poller(kwargs.get('async_mode', False))}[{super().type_annotation(**kwargs)}]"
238
238
 
239
239
  def docstring_type(self, **kwargs: Any) -> str:
240
- return f"~{self.get_poller_path(kwargs.pop('async_mode'))}[{super().docstring_type(**kwargs)}]"
240
+ return f"~{self.get_poller_path(kwargs.get('async_mode', False))}[{super().docstring_type(**kwargs)}]"
241
241
 
242
242
  def docstring_text(self, **kwargs) -> str:
243
243
  super_text = super().docstring_text(**kwargs)
244
- base_description = (
245
- f"An instance of {self.get_poller(kwargs.pop('async_mode'))} that returns "
246
- )
244
+ base_description = f"An instance of {self.get_poller(kwargs.get('async_mode', False))} that returns "
247
245
  if not self.code_model.options["version_tolerant"]:
248
246
  base_description += "either "
249
247
  return base_description + super_text
@@ -297,11 +295,11 @@ class LROResponse(Response):
297
295
  class LROPagingResponse(LROResponse, PagingResponse):
298
296
  def type_annotation(self, **kwargs: Any) -> str:
299
297
  paging_type_annotation = PagingResponse.type_annotation(self, **kwargs)
300
- return f"{self.get_poller(kwargs.pop('async_mode'))}[{paging_type_annotation}]"
298
+ return f"{self.get_poller(kwargs.get('async_mode', False))}[{paging_type_annotation}]"
301
299
 
302
300
  def docstring_type(self, **kwargs: Any) -> str:
303
301
  paging_docstring_type = PagingResponse.docstring_type(self, **kwargs)
304
- return f"~{self.get_poller_path(kwargs.pop('async_mode'))}[{paging_docstring_type}]"
302
+ return f"~{self.get_poller_path(kwargs.get('async_mode', False))}[{paging_docstring_type}]"
305
303
 
306
304
  def docstring_text(self, **kwargs) -> str:
307
305
  base_description = (
@@ -1043,6 +1043,8 @@ class _OperationSerializer(
1043
1043
  retval.append(" 404: ResourceNotFoundError,")
1044
1044
  if not 409 in builder.non_default_error_status_codes:
1045
1045
  retval.append(" 409: ResourceExistsError,")
1046
+ if not 304 in builder.non_default_error_status_codes:
1047
+ retval.append(" 304: ResourceNotModifiedError,")
1046
1048
  for excep in builder.non_default_errors:
1047
1049
  error_model_str = ""
1048
1050
  if (
@@ -1071,6 +1073,11 @@ class _OperationSerializer(
1071
1073
  " 409: lambda response: ResourceExistsError(response=response"
1072
1074
  f"{error_model_str}{error_format_str}),"
1073
1075
  )
1076
+ elif status_code == 304:
1077
+ retval.append(
1078
+ " 304: lambda response: ResourceNotModifiedError(response=response"
1079
+ f"{error_model_str}{error_format_str}),"
1080
+ )
1074
1081
  elif not error_model_str and not error_format_str:
1075
1082
  retval.append(f" {status_code}: HttpResponseError,")
1076
1083
  else:
@@ -1080,7 +1087,8 @@ class _OperationSerializer(
1080
1087
  )
1081
1088
  else:
1082
1089
  retval.append(
1083
- " 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError"
1090
+ " 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, "
1091
+ "304: ResourceNotModifiedError"
1084
1092
  )
1085
1093
  retval.append("}")
1086
1094
  retval.append("error_map.update(kwargs.pop('error_map', {}) or {})")
@@ -426,6 +426,10 @@ class M4Reformatter(
426
426
  ): # pylint: disable=too-many-public-methods
427
427
  """Add Python naming information."""
428
428
 
429
+ def __init__(self, *args, **kwargs) -> None:
430
+ super().__init__(*args, **kwargs)
431
+ self.check_client_input: bool = False
432
+
429
433
  @property
430
434
  def azure_arm(self) -> bool:
431
435
  return bool(self._autorestapi.get_boolean_value("azure-arm"))
@@ -802,7 +806,7 @@ class M4Reformatter(
802
806
  param["inDocstring"] = False
803
807
  if self.legacy:
804
808
  param["implementation"] = "Method"
805
- param["checkClientInput"] = True
809
+ param["checkClientInput"] = self.check_client_input
806
810
  if has_flattened_body and param.get("targetProperty"):
807
811
  retval.append(self.update_flattened_parameter(param, body_parameter))
808
812
  continue
@@ -935,6 +939,8 @@ class M4Reformatter(
935
939
 
936
940
  client_name = "base_url" if self.legacy else "endpoint"
937
941
  global_parameter["language"]["default"]["description"] = "Service URL."
942
+ elif name == "api_version":
943
+ self.check_client_input = True
938
944
  global_params.append(
939
945
  self.update_parameter(
940
946
  global_parameter, override_client_name=client_name
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.1.4",
3
+ "version": "6.1.5",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "scripts": {
6
6
  "prepare": "node run-python3.js prepare.py",