@autorest/python 6.28.3 → 6.29.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.
@@ -60,8 +60,19 @@ class BlackScriptPlugin(Plugin):
60
60
  except:
61
61
  _LOGGER.error("Error: failed to format %s", file)
62
62
  raise
63
- if len(file_content.splitlines()) > 1000 and "pylint: disable=too-many-lines" not in file_content:
64
- file_content = "# pylint: disable=too-many-lines\n" + file_content
63
+ pylint_disables = []
64
+ lines = file_content.splitlines()
65
+ if len(lines) > 0:
66
+ if "line-too-long" not in lines[0] and any(len(line) > 120 for line in lines):
67
+ pylint_disables.extend(["line-too-long", "useless-suppression"])
68
+ if "too-many-lines" not in lines[0] and len(lines) > 1000:
69
+ pylint_disables.append("too-many-lines")
70
+ if pylint_disables:
71
+ file_content = (
72
+ "\n".join([lines[0] + ",".join([""] + pylint_disables)] + lines[1:])
73
+ if "pylint: disable=" in lines[0]
74
+ else f"# pylint: disable={','.join(pylint_disables)}\n" + file_content
75
+ )
65
76
  self.write_file(file, file_content)
66
77
 
67
78
 
@@ -161,14 +161,6 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
161
161
  retval = add_to_pylint_disable(retval, "name-too-long")
162
162
  return retval
163
163
 
164
- @property
165
- def url_pylint_disable(self) -> str:
166
- # if the url is too long
167
- retval = ""
168
- if len(self.url) > 85:
169
- retval = add_to_pylint_disable(retval, "line-too-long")
170
- return retval
171
-
172
164
  @property
173
165
  def filename(self) -> str:
174
166
  """Name of the file for the client"""
@@ -498,11 +498,7 @@ class RequestBuilderSerializer(_BuilderBaseSerializer[RequestBuilderType]):
498
498
  url_value = _escape_str(builder.url)
499
499
  else:
500
500
  url_value = f'kwargs.pop("template_url", {_escape_str(builder.url)})'
501
- result = "_url = " + url_value
502
- # there will be always 4 spaces before the url
503
- if len(result) + 4 > 120:
504
- return result + " # pylint: disable=line-too-long"
505
- return result
501
+ return "_url = " + url_value
506
502
 
507
503
 
508
504
  ############################## NORMAL OPERATIONS ##############################
@@ -1005,7 +1001,9 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
1005
1001
  retval.extend(deserialize_code)
1006
1002
  return retval
1007
1003
 
1008
- def handle_error_response(self, builder: OperationType) -> List[str]: # pylint: disable=too-many-statements, too-many-branches
1004
+ def handle_error_response( # pylint: disable=too-many-statements, too-many-branches
1005
+ self, builder: OperationType
1006
+ ) -> List[str]:
1009
1007
  async_await = "await " if self.async_mode else ""
1010
1008
  retval = [f"if response.status_code not in {str(builder.success_status_codes)}:"]
1011
1009
  response_read = [
@@ -1042,34 +1040,23 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
1042
1040
  )
1043
1041
  # add build-in error type
1044
1042
  # TODO: we should decide whether need to this wrapper for customized error type
1045
- if status_code == 401:
1046
- retval.append(
1047
- " raise ClientAuthenticationError(response=response{}{})".format(
1048
- error_model,
1049
- (", error_format=ARMErrorFormat" if self.code_model.options["azure_arm"] else ""),
1050
- )
1051
- )
1052
- elif status_code == 404:
1053
- retval.append(
1054
- " raise ResourceNotFoundError(response=response{}{})".format(
1055
- error_model,
1056
- (", error_format=ARMErrorFormat" if self.code_model.options["azure_arm"] else ""),
1057
- )
1058
- )
1059
- elif status_code == 409:
1060
- retval.append(
1061
- " raise ResourceExistsError(response=response{}{})".format(
1062
- error_model,
1063
- (", error_format=ARMErrorFormat" if self.code_model.options["azure_arm"] else ""),
1064
- )
1065
- )
1066
- elif status_code == 304:
1043
+ status_code_error_map = {
1044
+ 401: "ClientAuthenticationError",
1045
+ 404: "ResourceNotFoundError",
1046
+ 409: "ResourceExistsError",
1047
+ 304: "ResourceNotModifiedError",
1048
+ }
1049
+ if status_code in status_code_error_map:
1067
1050
  retval.append(
1068
- " raise ResourceNotModifiedError(response=response{}{})".format(
1051
+ " raise {}(response=response{}{})".format(
1052
+ status_code_error_map[cast(int, status_code)],
1069
1053
  error_model,
1070
1054
  (", error_format=ARMErrorFormat" if self.code_model.options["azure_arm"] else ""),
1071
1055
  )
1072
1056
  )
1057
+ condition = "if"
1058
+ else:
1059
+ condition = "elif"
1073
1060
  # ranged status code only exist in typespec and will not have multiple status codes
1074
1061
  else:
1075
1062
  retval.append(
@@ -1084,15 +1071,13 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
1084
1071
  f" error = _failsafe_deserialize_xml({type_annotation}, response.text())"
1085
1072
  )
1086
1073
  else:
1087
- retval.append(
1088
- f" error = _failsafe_deserialize({type_annotation}, response.json())"
1089
- )
1074
+ retval.append(f" error = _failsafe_deserialize({type_annotation}, response.json())")
1090
1075
  else:
1091
1076
  retval.append(
1092
1077
  f" error = self._deserialize.failsafe_deserialize({type_annotation}, "
1093
1078
  "pipeline_response)"
1094
1079
  )
1095
- condition = "elif"
1080
+ condition = "elif"
1096
1081
  # default error handling
1097
1082
  if builder.default_error_deserialization and self.code_model.options["models_mode"]:
1098
1083
  error_model = ", model=error"
@@ -325,13 +325,7 @@ class DpgModelSerializer(_ModelSerializer):
325
325
  )
326
326
  type_annotation = prop.type_annotation(serialize_namespace=self.serialize_namespace)
327
327
  generated_code = f'{prop.client_name}: {type_annotation} = {field}({", ".join(args)})'
328
- # there is 4 spaces indentation so original line length limit 120 - 4 = 116
329
- pylint_disable = (
330
- " # pylint: disable=line-too-long"
331
- if len(generated_code) <= 116 < (len(generated_code) + len(type_ignore))
332
- else ""
333
- )
334
- return f"{generated_code}{type_ignore}{pylint_disable}"
328
+ return f"{generated_code}{type_ignore}"
335
329
 
336
330
  def initialize_properties(self, model: ModelType) -> List[str]:
337
331
  init_args = []
@@ -7,7 +7,7 @@
7
7
  super().__init__()
8
8
  {% endif %}
9
9
  {% if client.has_parameterized_host %}
10
- {{ serializer.host_variable_name }} = {{ keywords.escape_str(client.url) }}{{ client.url_pylint_disable }}
10
+ {{ serializer.host_variable_name }} = {{ keywords.escape_str(client.url) }}
11
11
  {% endif %}
12
12
  {{ serializer.initialize_config() }}
13
13
  {{ op_tools.serialize(serializer.initialize_pipeline_client(async_mode)) | indent(8) }}
@@ -4,10 +4,6 @@
4
4
  {% for line in list_result %}
5
5
  {% set prefix = "" if loop.index == 1 else " " %}
6
6
  {% set suffix = suffix_string if list_result | length == loop.index %}
7
- {% if line | length > 120 %}
8
- {{ prefix }}{{ line + " # pylint: disable=line-too-long" }}{{ suffix }}
9
- {% else %}
10
7
  {{ prefix }}{{ line }}{{ suffix }}
11
- {% endif %}
12
8
  {% endfor %}
13
9
  {% endmacro %}
@@ -8,16 +8,6 @@
8
8
 
9
9
  {{ serializer.discriminator_docstring(model) | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}
10
10
  {% endif %}
11
- {% if model.has_readonly_or_constant_property %}
12
-
13
- Readonly variables are only populated by the server, and will be ignored when sending a request.
14
- {% endif %}
15
- {% if (model.properties | selectattr('optional', "equalto", false) | first) is defined %}
16
-
17
- {% if not model.is_usage_output %}
18
- All required parameters must be populated in order to send to server.
19
- {% endif %}
20
- {% endif %}
21
11
 
22
12
  {% if model.properties != None %}
23
13
  {% for p in model.properties %}
@@ -12,9 +12,6 @@
12
12
  {% for description in serializer.description_and_summary(builder) %}
13
13
  {% if description %}
14
14
  {% set description = wrap_string(description, wrapstring='\n') %}
15
- {% if (serializer.line_too_long(example_template) or ns.line_too_long) and loop.first %}
16
- # pylint: disable=line-too-long
17
- {% endif %}
18
15
  {{ '"""' + description if loop.first else description }}
19
16
  {% else %}
20
17
 
@@ -410,7 +410,7 @@ class Model:
410
410
  :param function key_extractors: A key extractor function.
411
411
  :param str content_type: JSON by default, set application/xml if XML.
412
412
  :returns: An instance of this model
413
- :raises: DeserializationError if something went wrong
413
+ :raises DeserializationError: if something went wrong
414
414
  :rtype: Self
415
415
  """
416
416
  deserializer = Deserializer(cls._infer_class_models())
@@ -1360,7 +1360,7 @@ def xml_key_extractor(attr, attr_desc, data): # pylint: disable=unused-argument
1360
1360
  # Iter and wrapped, should have found one node only (the wrap one)
1361
1361
  if len(children) != 1:
1362
1362
  raise DeserializationError(
1363
- "Tried to deserialize an array not wrapped, and found several nodes '{}'. Maybe you should declare this array as wrapped?".format( # pylint: disable=line-too-long
1363
+ "Tried to deserialize an array not wrapped, and found several nodes '{}'. Maybe you should declare this array as wrapped?".format(
1364
1364
  xml_name
1365
1365
  )
1366
1366
  )
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": "1",
3
- "pip_version": "25.0",
3
+ "pip_version": "25.0.1",
4
4
  "install": [
5
5
  {
6
6
  "download_info": {
@@ -126,9 +126,9 @@
126
126
  "implementation_version": "3.8.10",
127
127
  "os_name": "posix",
128
128
  "platform_machine": "x86_64",
129
- "platform_release": "5.15.0-1079-azure",
129
+ "platform_release": "5.15.0-1081-azure",
130
130
  "platform_system": "Linux",
131
- "platform_version": "#88~20.04.1-Ubuntu SMP Fri Jan 17 18:28:29 UTC 2025",
131
+ "platform_version": "#90~20.04.1-Ubuntu SMP Tue Jan 28 05:34:18 UTC 2025",
132
132
  "python_full_version": "3.8.10",
133
133
  "platform_python_implementation": "CPython",
134
134
  "python_version": "3.8",
@@ -60,8 +60,19 @@ class BlackScriptPlugin(Plugin):
60
60
  except:
61
61
  _LOGGER.error("Error: failed to format %s", file)
62
62
  raise
63
- if len(file_content.splitlines()) > 1000 and "pylint: disable=too-many-lines" not in file_content:
64
- file_content = "# pylint: disable=too-many-lines\n" + file_content
63
+ pylint_disables = []
64
+ lines = file_content.splitlines()
65
+ if len(lines) > 0:
66
+ if "line-too-long" not in lines[0] and any(len(line) > 120 for line in lines):
67
+ pylint_disables.extend(["line-too-long", "useless-suppression"])
68
+ if "too-many-lines" not in lines[0] and len(lines) > 1000:
69
+ pylint_disables.append("too-many-lines")
70
+ if pylint_disables:
71
+ file_content = (
72
+ "\n".join([lines[0] + ",".join([""] + pylint_disables)] + lines[1:])
73
+ if "pylint: disable=" in lines[0]
74
+ else f"# pylint: disable={','.join(pylint_disables)}\n" + file_content
75
+ )
65
76
  self.write_file(file, file_content)
66
77
 
67
78
 
@@ -161,14 +161,6 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
161
161
  retval = add_to_pylint_disable(retval, "name-too-long")
162
162
  return retval
163
163
 
164
- @property
165
- def url_pylint_disable(self) -> str:
166
- # if the url is too long
167
- retval = ""
168
- if len(self.url) > 85:
169
- retval = add_to_pylint_disable(retval, "line-too-long")
170
- return retval
171
-
172
164
  @property
173
165
  def filename(self) -> str:
174
166
  """Name of the file for the client"""
@@ -498,11 +498,7 @@ class RequestBuilderSerializer(_BuilderBaseSerializer[RequestBuilderType]):
498
498
  url_value = _escape_str(builder.url)
499
499
  else:
500
500
  url_value = f'kwargs.pop("template_url", {_escape_str(builder.url)})'
501
- result = "_url = " + url_value
502
- # there will be always 4 spaces before the url
503
- if len(result) + 4 > 120:
504
- return result + " # pylint: disable=line-too-long"
505
- return result
501
+ return "_url = " + url_value
506
502
 
507
503
 
508
504
  ############################## NORMAL OPERATIONS ##############################
@@ -1005,7 +1001,9 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
1005
1001
  retval.extend(deserialize_code)
1006
1002
  return retval
1007
1003
 
1008
- def handle_error_response(self, builder: OperationType) -> List[str]: # pylint: disable=too-many-statements, too-many-branches
1004
+ def handle_error_response( # pylint: disable=too-many-statements, too-many-branches
1005
+ self, builder: OperationType
1006
+ ) -> List[str]:
1009
1007
  async_await = "await " if self.async_mode else ""
1010
1008
  retval = [f"if response.status_code not in {str(builder.success_status_codes)}:"]
1011
1009
  response_read = [
@@ -1042,34 +1040,23 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
1042
1040
  )
1043
1041
  # add build-in error type
1044
1042
  # TODO: we should decide whether need to this wrapper for customized error type
1045
- if status_code == 401:
1046
- retval.append(
1047
- " raise ClientAuthenticationError(response=response{}{})".format(
1048
- error_model,
1049
- (", error_format=ARMErrorFormat" if self.code_model.options["azure_arm"] else ""),
1050
- )
1051
- )
1052
- elif status_code == 404:
1053
- retval.append(
1054
- " raise ResourceNotFoundError(response=response{}{})".format(
1055
- error_model,
1056
- (", error_format=ARMErrorFormat" if self.code_model.options["azure_arm"] else ""),
1057
- )
1058
- )
1059
- elif status_code == 409:
1060
- retval.append(
1061
- " raise ResourceExistsError(response=response{}{})".format(
1062
- error_model,
1063
- (", error_format=ARMErrorFormat" if self.code_model.options["azure_arm"] else ""),
1064
- )
1065
- )
1066
- elif status_code == 304:
1043
+ status_code_error_map = {
1044
+ 401: "ClientAuthenticationError",
1045
+ 404: "ResourceNotFoundError",
1046
+ 409: "ResourceExistsError",
1047
+ 304: "ResourceNotModifiedError",
1048
+ }
1049
+ if status_code in status_code_error_map:
1067
1050
  retval.append(
1068
- " raise ResourceNotModifiedError(response=response{}{})".format(
1051
+ " raise {}(response=response{}{})".format(
1052
+ status_code_error_map[cast(int, status_code)],
1069
1053
  error_model,
1070
1054
  (", error_format=ARMErrorFormat" if self.code_model.options["azure_arm"] else ""),
1071
1055
  )
1072
1056
  )
1057
+ condition = "if"
1058
+ else:
1059
+ condition = "elif"
1073
1060
  # ranged status code only exist in typespec and will not have multiple status codes
1074
1061
  else:
1075
1062
  retval.append(
@@ -1084,15 +1071,13 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
1084
1071
  f" error = _failsafe_deserialize_xml({type_annotation}, response.text())"
1085
1072
  )
1086
1073
  else:
1087
- retval.append(
1088
- f" error = _failsafe_deserialize({type_annotation}, response.json())"
1089
- )
1074
+ retval.append(f" error = _failsafe_deserialize({type_annotation}, response.json())")
1090
1075
  else:
1091
1076
  retval.append(
1092
1077
  f" error = self._deserialize.failsafe_deserialize({type_annotation}, "
1093
1078
  "pipeline_response)"
1094
1079
  )
1095
- condition = "elif"
1080
+ condition = "elif"
1096
1081
  # default error handling
1097
1082
  if builder.default_error_deserialization and self.code_model.options["models_mode"]:
1098
1083
  error_model = ", model=error"
@@ -325,13 +325,7 @@ class DpgModelSerializer(_ModelSerializer):
325
325
  )
326
326
  type_annotation = prop.type_annotation(serialize_namespace=self.serialize_namespace)
327
327
  generated_code = f'{prop.client_name}: {type_annotation} = {field}({", ".join(args)})'
328
- # there is 4 spaces indentation so original line length limit 120 - 4 = 116
329
- pylint_disable = (
330
- " # pylint: disable=line-too-long"
331
- if len(generated_code) <= 116 < (len(generated_code) + len(type_ignore))
332
- else ""
333
- )
334
- return f"{generated_code}{type_ignore}{pylint_disable}"
328
+ return f"{generated_code}{type_ignore}"
335
329
 
336
330
  def initialize_properties(self, model: ModelType) -> List[str]:
337
331
  init_args = []
@@ -7,7 +7,7 @@
7
7
  super().__init__()
8
8
  {% endif %}
9
9
  {% if client.has_parameterized_host %}
10
- {{ serializer.host_variable_name }} = {{ keywords.escape_str(client.url) }}{{ client.url_pylint_disable }}
10
+ {{ serializer.host_variable_name }} = {{ keywords.escape_str(client.url) }}
11
11
  {% endif %}
12
12
  {{ serializer.initialize_config() }}
13
13
  {{ op_tools.serialize(serializer.initialize_pipeline_client(async_mode)) | indent(8) }}
@@ -4,10 +4,6 @@
4
4
  {% for line in list_result %}
5
5
  {% set prefix = "" if loop.index == 1 else " " %}
6
6
  {% set suffix = suffix_string if list_result | length == loop.index %}
7
- {% if line | length > 120 %}
8
- {{ prefix }}{{ line + " # pylint: disable=line-too-long" }}{{ suffix }}
9
- {% else %}
10
7
  {{ prefix }}{{ line }}{{ suffix }}
11
- {% endif %}
12
8
  {% endfor %}
13
9
  {% endmacro %}
@@ -8,16 +8,6 @@
8
8
 
9
9
  {{ serializer.discriminator_docstring(model) | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}
10
10
  {% endif %}
11
- {% if model.has_readonly_or_constant_property %}
12
-
13
- Readonly variables are only populated by the server, and will be ignored when sending a request.
14
- {% endif %}
15
- {% if (model.properties | selectattr('optional', "equalto", false) | first) is defined %}
16
-
17
- {% if not model.is_usage_output %}
18
- All required parameters must be populated in order to send to server.
19
- {% endif %}
20
- {% endif %}
21
11
 
22
12
  {% if model.properties != None %}
23
13
  {% for p in model.properties %}
@@ -12,9 +12,6 @@
12
12
  {% for description in serializer.description_and_summary(builder) %}
13
13
  {% if description %}
14
14
  {% set description = wrap_string(description, wrapstring='\n') %}
15
- {% if (serializer.line_too_long(example_template) or ns.line_too_long) and loop.first %}
16
- # pylint: disable=line-too-long
17
- {% endif %}
18
15
  {{ '"""' + description if loop.first else description }}
19
16
  {% else %}
20
17
 
@@ -410,7 +410,7 @@ class Model:
410
410
  :param function key_extractors: A key extractor function.
411
411
  :param str content_type: JSON by default, set application/xml if XML.
412
412
  :returns: An instance of this model
413
- :raises: DeserializationError if something went wrong
413
+ :raises DeserializationError: if something went wrong
414
414
  :rtype: Self
415
415
  """
416
416
  deserializer = Deserializer(cls._infer_class_models())
@@ -1360,7 +1360,7 @@ def xml_key_extractor(attr, attr_desc, data): # pylint: disable=unused-argument
1360
1360
  # Iter and wrapped, should have found one node only (the wrap one)
1361
1361
  if len(children) != 1:
1362
1362
  raise DeserializationError(
1363
- "Tried to deserialize an array not wrapped, and found several nodes '{}'. Maybe you should declare this array as wrapped?".format( # pylint: disable=line-too-long
1363
+ "Tried to deserialize an array not wrapped, and found several nodes '{}'. Maybe you should declare this array as wrapped?".format(
1364
1364
  xml_name
1365
1365
  )
1366
1366
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.28.3",
3
+ "version": "6.29.0",
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.6.10",
22
+ "@typespec/http-client-python": "~0.7.0",
23
23
  "@autorest/system-requirements": "~1.0.2",
24
24
  "fs-extra": "~11.2.0",
25
25
  "tsx": "~4.19.1"