Skip to content

Commit d7b17df

Browse files
msyyciscai-msft
andauthored
[python] Bump tsp 0.65.0 (#5967)
Co-authored-by: iscai-msft <[email protected]>
1 parent ea5124e commit d7b17df

File tree

13 files changed

+3452
-1080
lines changed

13 files changed

+3452
-1080
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: dependencies
3+
packages:
4+
- "@typespec/http-client-python"
5+
---
6+
7+
Bump to tsp 0.65.0

packages/http-client-python/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log - @typespec/http-client-python
22

3+
## 0.6.11
4+
5+
No changes, version bump only.
6+
37
## 0.6.10
48

59
### Bug Fixes

packages/http-client-python/eng/scripts/ci/regenerate.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ async function getSubdirectories(baseDir: string, flags: RegenerateFlags): Promi
220220
// after fix test generation for nested operation group, remove this check
221221
if (mainTspRelativePath.includes("client-operation-group")) return;
222222

223+
// after https://github.com/Azure/autorest.python/issues/3043 fixed, remove this check
224+
if (mainTspRelativePath.includes("azure/client-generator-core/api-version")) return;
225+
223226
const hasMainTsp = await promises
224227
.access(mainTspPath)
225228
.then(() => true)

packages/http-client-python/generator/pygen/black.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,19 @@ def format_file(self, file: Path) -> None:
6060
except:
6161
_LOGGER.error("Error: failed to format %s", file)
6262
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+
)
6576
self.write_file(file, file_content)
6677

6778

packages/http-client-python/generator/pygen/codegen/models/client.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,6 @@ def pylint_disable(self) -> str:
161161
retval = add_to_pylint_disable(retval, "name-too-long")
162162
return retval
163163

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-
172164
@property
173165
def filename(self) -> str:
174166
"""Name of the file for the client"""

packages/http-client-python/generator/pygen/codegen/serializers/builder_serializer.py

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,7 @@ def construct_url(self, builder: RequestBuilderType) -> str:
498498
url_value = _escape_str(builder.url)
499499
else:
500500
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
506502

507503

508504
############################## NORMAL OPERATIONS ##############################
@@ -1005,7 +1001,9 @@ def response_deserialization( # pylint: disable=too-many-statements
10051001
retval.extend(deserialize_code)
10061002
return retval
10071003

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]:
10091007
async_await = "await " if self.async_mode else ""
10101008
retval = [f"if response.status_code not in {str(builder.success_status_codes)}:"]
10111009
response_read = [
@@ -1042,34 +1040,23 @@ def handle_error_response(self, builder: OperationType) -> List[str]: # pylint
10421040
)
10431041
# add build-in error type
10441042
# 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:
10671050
retval.append(
1068-
" raise ResourceNotModifiedError(response=response{}{})".format(
1051+
" raise {}(response=response{}{})".format(
1052+
status_code_error_map[cast(int, status_code)],
10691053
error_model,
10701054
(", error_format=ARMErrorFormat" if self.code_model.options["azure_arm"] else ""),
10711055
)
10721056
)
1057+
condition = "if"
1058+
else:
1059+
condition = "elif"
10731060
# ranged status code only exist in typespec and will not have multiple status codes
10741061
else:
10751062
retval.append(
@@ -1084,15 +1071,13 @@ def handle_error_response(self, builder: OperationType) -> List[str]: # pylint
10841071
f" error = _failsafe_deserialize_xml({type_annotation}, response.text())"
10851072
)
10861073
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())")
10901075
else:
10911076
retval.append(
10921077
f" error = self._deserialize.failsafe_deserialize({type_annotation}, "
10931078
"pipeline_response)"
10941079
)
1095-
condition = "elif"
1080+
condition = "elif"
10961081
# default error handling
10971082
if builder.default_error_deserialization and self.code_model.options["models_mode"]:
10981083
error_model = ", model=error"

packages/http-client-python/generator/pygen/codegen/serializers/model_serializer.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,7 @@ def declare_property(self, prop: Property) -> str:
325325
)
326326
type_annotation = prop.type_annotation(serialize_namespace=self.serialize_namespace)
327327
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}"
335329

336330
def initialize_properties(self, model: ModelType) -> List[str]:
337331
init_args = []

packages/http-client-python/generator/pygen/codegen/templates/client.py.jinja2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
super().__init__()
88
{% endif %}
99
{% 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) }}
1111
{% endif %}
1212
{{ serializer.initialize_config() }}
1313
{{ op_tools.serialize(serializer.initialize_pipeline_client(async_mode)) | indent(8) }}

packages/http-client-python/generator/pygen/codegen/templates/macros.jinja2

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
{% for line in list_result %}
55
{% set prefix = "" if loop.index == 1 else " " %}
66
{% 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 %}
107
{{ prefix }}{{ line }}{{ suffix }}
11-
{% endif %}
128
{% endfor %}
139
{% endmacro %}

packages/http-client-python/generator/pygen/codegen/templates/operation_tools.jinja2

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
{% for description in serializer.description_and_summary(builder) %}
1313
{% if description %}
1414
{% 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 %}
1815
{{ '"""' + description if loop.first else description }}
1916
{% else %}
2017

0 commit comments

Comments
 (0)