@autorest/python 6.27.0 → 6.27.2

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.
@@ -51,6 +51,7 @@ class BlackScriptPlugin(Plugin):
51
51
  return True
52
52
 
53
53
  def format_file(self, file: Path) -> None:
54
+ file_content = ""
54
55
  try:
55
56
  file_content = self.read_file(file)
56
57
  file_content = black.format_file_contents(file_content, fast=True, mode=_BLACK_MODE)
@@ -249,8 +249,15 @@ class CodeGenerator(Plugin):
249
249
  if not operation.get("exceptions"):
250
250
  continue
251
251
  # sort exceptions by status code, first single status code, then range, then default
252
- operation["exceptions"] = sorted(operation["exceptions"], key=lambda x: 3 if x["statusCodes"][0] == "default" else (1 if isinstance(x["statusCodes"][0], int) else 2))
253
-
252
+ operation["exceptions"] = sorted(
253
+ operation["exceptions"],
254
+ key=lambda x: (
255
+ 3
256
+ if x["statusCodes"][0] == "default"
257
+ else (1 if isinstance(x["statusCodes"][0], int) else 2)
258
+ ),
259
+ )
260
+
254
261
  @staticmethod
255
262
  def remove_cloud_errors(yaml_data: Dict[str, Any]) -> None:
256
263
  for client in yaml_data["clients"]:
@@ -325,7 +332,7 @@ class CodeGenerator(Plugin):
325
332
  self._validate_code_model_options()
326
333
  options = self._build_code_model_options()
327
334
  yaml_data = self.get_yaml()
328
-
335
+
329
336
  self.sort_exceptions(yaml_data)
330
337
 
331
338
  if self.options_retriever.azure_arm:
@@ -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
6
+ from typing import Any, List, 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):
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
 
@@ -3,19 +3,16 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- from itertools import chain
7
6
  from typing import (
8
7
  Dict,
9
8
  List,
10
9
  Any,
11
10
  Optional,
12
- Tuple,
13
11
  Union,
14
12
  TYPE_CHECKING,
15
13
  Generic,
16
14
  TypeVar,
17
15
  cast,
18
- Sequence,
19
16
  )
20
17
 
21
18
  from .request_builder_parameter import RequestBuilderParameter
@@ -206,7 +203,9 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
206
203
 
207
204
  @property
208
205
  def non_default_errors(self) -> List[Response]:
209
- return [e for e in self.exceptions if "default" not in e.status_codes and e.type and isinstance(e.type, ModelType)]
206
+ return [
207
+ e for e in self.exceptions if "default" not in e.status_codes and e.type and isinstance(e.type, ModelType)
208
+ ]
210
209
 
211
210
  def _imports_shared(self, async_mode: bool, **kwargs: Any) -> FileImport: # pylint: disable=unused-argument
212
211
  file_import = FileImport(self.code_model)
@@ -419,7 +418,9 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
419
418
  elif any(r.type for r in self.responses):
420
419
  file_import.add_submodule_import(f"{relative_path}_model_base", "_deserialize", ImportType.LOCAL)
421
420
  if self.default_error_deserialization or self.non_default_errors:
422
- file_import.add_submodule_import(f"{relative_path}_model_base", "_failsafe_deserialize", ImportType.LOCAL)
421
+ file_import.add_submodule_import(
422
+ f"{relative_path}_model_base", "_failsafe_deserialize", ImportType.LOCAL
423
+ )
423
424
  return file_import
424
425
 
425
426
  def get_response_from_status(self, status_code: Optional[Union[str, int]]) -> ResponseType:
@@ -429,7 +430,7 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
429
430
  raise ValueError(f"Incorrect status code {status_code}, operation {self.name}") from exc
430
431
 
431
432
  @property
432
- def success_status_codes(self) -> Sequence[Union[str, int]]:
433
+ def success_status_codes(self) -> List[Union[int, str, List[int]]]:
433
434
  """The list of all successfull status code."""
434
435
  return sorted([code for response in self.responses for code in response.status_codes])
435
436
 
@@ -991,9 +991,7 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
991
991
  elif isinstance(builder.stream_value, str): # _stream is not sure, so we need to judge it
992
992
  retval.append(" if _stream:")
993
993
  retval.extend([f" {l}" for l in response_read])
994
- retval.append(
995
- f" map_error(status_code=response.status_code, response=response, error_map=error_map)"
996
- )
994
+ retval.append(" map_error(status_code=response.status_code, response=response, error_map=error_map)")
997
995
  error_model = ""
998
996
  if builder.non_default_errors and self.code_model.options["models_mode"]:
999
997
  error_model = ", model=error"
@@ -1005,10 +1003,10 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
1005
1003
  for status_code in e.status_codes:
1006
1004
  retval.append(f" {condition} response.status_code == {status_code}:")
1007
1005
  if self.code_model.options["models_mode"] == "dpg":
1008
- retval.append(f" error = _failsafe_deserialize({e.type.type_annotation(is_operation_file=True, skip_quote=True)}, response.json())")
1006
+ retval.append(f" error = _failsafe_deserialize({e.type.type_annotation(is_operation_file=True, skip_quote=True)}, response.json())") # type: ignore # pylint: disable=line-too-long
1009
1007
  else:
1010
1008
  retval.append(
1011
- f" error = self._deserialize.failsafe_deserialize({e.type.type_annotation(is_operation_file=True, skip_quote=True)}, "
1009
+ f" error = self._deserialize.failsafe_deserialize({e.type.type_annotation(is_operation_file=True, skip_quote=True)}, " # type: ignore # pylint: disable=line-too-long
1012
1010
  "pipeline_response)"
1013
1011
  )
1014
1012
  # add build-in error type
@@ -1043,12 +1041,14 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
1043
1041
  )
1044
1042
  # ranged status code only exist in typespec and will not have multiple status codes
1045
1043
  else:
1046
- retval.append(f" {condition} {e.status_codes[0][0]} <= response.status_code <= {e.status_codes[0][1]}:")
1044
+ retval.append(
1045
+ f" {condition} {e.status_codes[0][0]} <= response.status_code <= {e.status_codes[0][1]}:"
1046
+ )
1047
1047
  if self.code_model.options["models_mode"] == "dpg":
1048
- retval.append(f" error = _failsafe_deserialize({e.type.type_annotation(is_operation_file=True, skip_quote=True)}, response.json())")
1048
+ retval.append(f" error = _failsafe_deserialize({e.type.type_annotation(is_operation_file=True, skip_quote=True)}, response.json())") # type: ignore # pylint: disable=line-too-long
1049
1049
  else:
1050
1050
  retval.append(
1051
- f" error = self._deserialize.failsafe_deserialize({e.type.type_annotation(is_operation_file=True, skip_quote=True)}, "
1051
+ f" error = self._deserialize.failsafe_deserialize({e.type.type_annotation(is_operation_file=True, skip_quote=True)}, " # type: ignore # pylint: disable=line-too-long
1052
1052
  "pipeline_response)"
1053
1053
  )
1054
1054
  condition = "elif"
@@ -1059,7 +1059,9 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
1059
1059
  if builder.non_default_errors:
1060
1060
  retval.append(" else:")
1061
1061
  if self.code_model.options["models_mode"] == "dpg":
1062
- retval.append(f"{indent}error = _failsafe_deserialize({builder.default_error_deserialization}, response.json())")
1062
+ retval.append(
1063
+ f"{indent}error = _failsafe_deserialize({builder.default_error_deserialization}, response.json())"
1064
+ )
1063
1065
  else:
1064
1066
  retval.append(
1065
1067
  f"{indent}error = self._deserialize.failsafe_deserialize({builder.default_error_deserialization}, "
@@ -1086,7 +1088,7 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
1086
1088
  if len(builder.responses) > 1:
1087
1089
  status_codes, res_headers, res_deserialization = [], [], []
1088
1090
  for status_code in builder.success_status_codes:
1089
- response = builder.get_response_from_status(status_code)
1091
+ response = builder.get_response_from_status(status_code) # type: ignore
1090
1092
  if response.headers or response.type:
1091
1093
  status_codes.append(status_code)
1092
1094
  res_headers.append(self.response_headers(response))
@@ -1143,10 +1145,13 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
1143
1145
  if code in non_default_error.status_codes:
1144
1146
  return False
1145
1147
  # ranged status code
1146
- if isinstance(non_default_error.status_codes[0], list) and non_default_error.status_codes[0][0] <= code <= non_default_error.status_codes[0][1]:
1148
+ if (
1149
+ isinstance(non_default_error.status_codes[0], list)
1150
+ and non_default_error.status_codes[0][0] <= code <= non_default_error.status_codes[0][1]
1151
+ ):
1147
1152
  return False
1148
1153
  return True
1149
-
1154
+
1150
1155
  def error_map(self, builder: OperationType) -> List[str]:
1151
1156
  retval = ["error_map: MutableMapping = {"]
1152
1157
  if builder.non_default_errors and self.code_model.options["models_mode"]:
@@ -24,7 +24,7 @@ class GeneratorRenderer(m2r2.RestRenderer):
24
24
 
25
25
  def inline_html(self, html: str) -> str:
26
26
  """Do not render inline HTML with a role definition."""
27
- return f":code:`{html}`"
27
+ return r"\ :code:`{}`".format(html)
28
28
 
29
29
 
30
30
  class M2R(YamlUpdatePlugin):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.27.0",
3
+ "version": "6.27.2",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
21
21
  "dependencies": {
22
- "@typespec/http-client-python": "~0.4.2",
22
+ "@typespec/http-client-python": "~0.4.4",
23
23
  "@autorest/system-requirements": "~1.0.2",
24
24
  "fs-extra": "~11.2.0",
25
25
  "tsx": "~4.19.1"