Skip to content

Commit

Permalink
[python] Bump tsp 0.65.0 (#5967)
Browse files Browse the repository at this point in the history
Co-authored-by: iscai-msft <[email protected]>
  • Loading branch information
msyyc and iscai-msft authored Feb 14, 2025
1 parent ea5124e commit d7b17df
Show file tree
Hide file tree
Showing 13 changed files with 3,452 additions and 1,080 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/bum-tsp-0.65.0-2025-1-13-11-20-8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: dependencies
packages:
- "@typespec/http-client-python"
---

Bump to tsp 0.65.0
4 changes: 4 additions & 0 deletions packages/http-client-python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log - @typespec/http-client-python

## 0.6.11

No changes, version bump only.

## 0.6.10

### Bug Fixes
Expand Down
3 changes: 3 additions & 0 deletions packages/http-client-python/eng/scripts/ci/regenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ async function getSubdirectories(baseDir: string, flags: RegenerateFlags): Promi
// after fix test generation for nested operation group, remove this check
if (mainTspRelativePath.includes("client-operation-group")) return;

// after https://github.com/Azure/autorest.python/issues/3043 fixed, remove this check
if (mainTspRelativePath.includes("azure/client-generator-core/api-version")) return;

const hasMainTsp = await promises
.access(mainTspPath)
.then(() => true)
Expand Down
15 changes: 13 additions & 2 deletions packages/http-client-python/generator/pygen/black.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,19 @@ def format_file(self, file: Path) -> None:
except:
_LOGGER.error("Error: failed to format %s", file)
raise
if len(file_content.splitlines()) > 1000 and "pylint: disable=too-many-lines" not in file_content:
file_content = "# pylint: disable=too-many-lines\n" + file_content
pylint_disables = []
lines = file_content.splitlines()
if len(lines) > 0:
if "line-too-long" not in lines[0] and any(len(line) > 120 for line in lines):
pylint_disables.extend(["line-too-long", "useless-suppression"])
if "too-many-lines" not in lines[0] and len(lines) > 1000:
pylint_disables.append("too-many-lines")
if pylint_disables:
file_content = (
"\n".join([lines[0] + ",".join([""] + pylint_disables)] + lines[1:])
if "pylint: disable=" in lines[0]
else f"# pylint: disable={','.join(pylint_disables)}\n" + file_content
)
self.write_file(file, file_content)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,6 @@ def pylint_disable(self) -> str:
retval = add_to_pylint_disable(retval, "name-too-long")
return retval

@property
def url_pylint_disable(self) -> str:
# if the url is too long
retval = ""
if len(self.url) > 85:
retval = add_to_pylint_disable(retval, "line-too-long")
return retval

@property
def filename(self) -> str:
"""Name of the file for the client"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,7 @@ def construct_url(self, builder: RequestBuilderType) -> str:
url_value = _escape_str(builder.url)
else:
url_value = f'kwargs.pop("template_url", {_escape_str(builder.url)})'
result = "_url = " + url_value
# there will be always 4 spaces before the url
if len(result) + 4 > 120:
return result + " # pylint: disable=line-too-long"
return result
return "_url = " + url_value


############################## NORMAL OPERATIONS ##############################
Expand Down Expand Up @@ -1005,7 +1001,9 @@ def response_deserialization( # pylint: disable=too-many-statements
retval.extend(deserialize_code)
return retval

def handle_error_response(self, builder: OperationType) -> List[str]: # pylint: disable=too-many-statements, too-many-branches
def handle_error_response( # pylint: disable=too-many-statements, too-many-branches
self, builder: OperationType
) -> List[str]:
async_await = "await " if self.async_mode else ""
retval = [f"if response.status_code not in {str(builder.success_status_codes)}:"]
response_read = [
Expand Down Expand Up @@ -1042,34 +1040,23 @@ def handle_error_response(self, builder: OperationType) -> List[str]: # pylint
)
# add build-in error type
# TODO: we should decide whether need to this wrapper for customized error type
if status_code == 401:
retval.append(
" raise ClientAuthenticationError(response=response{}{})".format(
error_model,
(", error_format=ARMErrorFormat" if self.code_model.options["azure_arm"] else ""),
)
)
elif status_code == 404:
retval.append(
" raise ResourceNotFoundError(response=response{}{})".format(
error_model,
(", error_format=ARMErrorFormat" if self.code_model.options["azure_arm"] else ""),
)
)
elif status_code == 409:
retval.append(
" raise ResourceExistsError(response=response{}{})".format(
error_model,
(", error_format=ARMErrorFormat" if self.code_model.options["azure_arm"] else ""),
)
)
elif status_code == 304:
status_code_error_map = {
401: "ClientAuthenticationError",
404: "ResourceNotFoundError",
409: "ResourceExistsError",
304: "ResourceNotModifiedError",
}
if status_code in status_code_error_map:
retval.append(
" raise ResourceNotModifiedError(response=response{}{})".format(
" raise {}(response=response{}{})".format(
status_code_error_map[cast(int, status_code)],
error_model,
(", error_format=ARMErrorFormat" if self.code_model.options["azure_arm"] else ""),
)
)
condition = "if"
else:
condition = "elif"
# ranged status code only exist in typespec and will not have multiple status codes
else:
retval.append(
Expand All @@ -1084,15 +1071,13 @@ def handle_error_response(self, builder: OperationType) -> List[str]: # pylint
f" error = _failsafe_deserialize_xml({type_annotation}, response.text())"
)
else:
retval.append(
f" error = _failsafe_deserialize({type_annotation}, response.json())"
)
retval.append(f" error = _failsafe_deserialize({type_annotation}, response.json())")
else:
retval.append(
f" error = self._deserialize.failsafe_deserialize({type_annotation}, "
"pipeline_response)"
)
condition = "elif"
condition = "elif"
# default error handling
if builder.default_error_deserialization and self.code_model.options["models_mode"]:
error_model = ", model=error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,7 @@ def declare_property(self, prop: Property) -> str:
)
type_annotation = prop.type_annotation(serialize_namespace=self.serialize_namespace)
generated_code = f'{prop.client_name}: {type_annotation} = {field}({", ".join(args)})'
# there is 4 spaces indentation so original line length limit 120 - 4 = 116
pylint_disable = (
" # pylint: disable=line-too-long"
if len(generated_code) <= 116 < (len(generated_code) + len(type_ignore))
else ""
)
return f"{generated_code}{type_ignore}{pylint_disable}"
return f"{generated_code}{type_ignore}"

def initialize_properties(self, model: ModelType) -> List[str]:
init_args = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
super().__init__()
{% endif %}
{% if client.has_parameterized_host %}
{{ serializer.host_variable_name }} = {{ keywords.escape_str(client.url) }}{{ client.url_pylint_disable }}
{{ serializer.host_variable_name }} = {{ keywords.escape_str(client.url) }}
{% endif %}
{{ serializer.initialize_config() }}
{{ op_tools.serialize(serializer.initialize_pipeline_client(async_mode)) | indent(8) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
{% for line in list_result %}
{% set prefix = "" if loop.index == 1 else " " %}
{% set suffix = suffix_string if list_result | length == loop.index %}
{% if line | length > 120 %}
{{ prefix }}{{ line + " # pylint: disable=line-too-long" }}{{ suffix }}
{% else %}
{{ prefix }}{{ line }}{{ suffix }}
{% endif %}
{% endfor %}
{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
{% for description in serializer.description_and_summary(builder) %}
{% if description %}
{% set description = wrap_string(description, wrapstring='\n') %}
{% if (serializer.line_too_long(example_template) or ns.line_too_long) and loop.first %}
# pylint: disable=line-too-long
{% endif %}
{{ '"""' + description if loop.first else description }}
{% else %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ def xml_key_extractor(attr, attr_desc, data): # pylint: disable=unused-argument
# Iter and wrapped, should have found one node only (the wrap one)
if len(children) != 1:
raise DeserializationError(
"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
"Tried to deserialize an array not wrapped, and found several nodes '{}'. Maybe you should declare this array as wrapped?".format(
xml_name
)
)
Expand Down
Loading

0 comments on commit d7b17df

Please sign in to comment.