Skip to content

Commit d7c8963

Browse files
authored
[http-client-python] Fix import of typing List (#3194)
* Update dependencies * Update dependencies (2025-09-03 06:00:19) * Regenerate for typespec-python (2025-09-03 06:05:16) * Regenerate for autorest.python (2025-09-03 06:19:51) * add changelog * add test case * fix test * add test case * Update dependencies * Update dependencies (2025-09-05 03:59:39) * Regenerate for typespec-python (2025-09-05 04:04:55) * Regenerate for autorest.python (2025-09-05 04:20:16) * update package.json * update lock file --------- Co-authored-by: AutoPrFromHttpClientPython <AutoPrFromHttpClientPython>
1 parent 653a94d commit d7c8963

File tree

40 files changed

+740
-37
lines changed

40 files changed

+740
-37
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
changeKind: fix
3+
packages:
4+
- "@autorest/python"
5+
- "@azure-tools/typespec-python"
6+
---
7+
8+
Fix dependencies of pyproject.toml for ARM SDK

packages/autorest.python/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
3131
"dependencies": {
32-
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTI5NDY5NC9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.16.0.tgz",
32+
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTMwMTc4Ni9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.16.0.tgz",
3333
"@autorest/system-requirements": "~1.0.2",
3434
"fs-extra": "~11.2.0",
3535
"tsx": "~4.19.1"
@@ -47,4 +47,4 @@
4747
"requirements.txt",
4848
"generator/"
4949
]
50-
}
50+
}

packages/autorest.python/samples/specification/azure-mgmt-pyproject/readme.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,65 @@ output-folder: $(python-sdks-folder)/test/azure-mgmt-pyproject/azure/mgmt/pyproj
2626
modelerfour:
2727
flatten-models: false
2828
```
29+
30+
``` yaml $(python)
31+
directive:
32+
- from: swagger-document
33+
where: $.paths
34+
transform: >
35+
$["/self-define/post1"] = {
36+
"post": {
37+
"operationId": "Operations_List",
38+
"summary": "Process list of strings",
39+
"description": "Processes a list of strings with no return value",
40+
"parameters": [
41+
{
42+
"name": "body",
43+
"in": "body",
44+
"required": true,
45+
"schema": {
46+
"type": "array",
47+
"items": {
48+
"type": "string"
49+
}
50+
},
51+
"description": "List of strings to process"
52+
}
53+
],
54+
"responses": {
55+
"204": {
56+
"description": "Operation completed successfully with no content"
57+
}
58+
}
59+
}
60+
};
61+
- from: swagger-document
62+
where: $.paths
63+
transform: >
64+
$["/self-define/post2"] = {
65+
"post": {
66+
"operationId": "SelfDefine_Post",
67+
"summary": "Process list of strings",
68+
"description": "Processes a list of strings with no return value",
69+
"parameters": [
70+
{
71+
"name": "body",
72+
"in": "body",
73+
"required": true,
74+
"schema": {
75+
"type": "array",
76+
"items": {
77+
"type": "string"
78+
}
79+
},
80+
"description": "List of strings to process"
81+
}
82+
],
83+
"responses": {
84+
"204": {
85+
"description": "Operation completed successfully with no content"
86+
}
87+
}
88+
}
89+
};
90+
```

packages/autorest.python/samples/specification/azure-mgmt-pyproject/test/azure-mgmt-pyproject/apiview-properties.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"azure.mgmt.pyproject.operations.HttpSuccessOperations.head204": null,
77
"azure.mgmt.pyproject.aio.operations.HttpSuccessOperations.head204": null,
88
"azure.mgmt.pyproject.operations.HttpSuccessOperations.head404": null,
9-
"azure.mgmt.pyproject.aio.operations.HttpSuccessOperations.head404": null
9+
"azure.mgmt.pyproject.aio.operations.HttpSuccessOperations.head404": null,
10+
"azure.mgmt.pyproject.operations.Operations.list": null,
11+
"azure.mgmt.pyproject.aio.operations.Operations.list": null,
12+
"azure.mgmt.pyproject.operations.SelfDefineOperations.post": null,
13+
"azure.mgmt.pyproject.aio.operations.SelfDefineOperations.post": null
1014
}
1115
}

packages/autorest.python/samples/specification/azure-mgmt-pyproject/test/azure-mgmt-pyproject/azure/mgmt/pyproject/_pyproject_mgmt_client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from ._configuration import PyprojectMgmtClientConfiguration
2121
from ._utils.serialization import Deserializer, Serializer
22-
from .operations import HttpSuccessOperations
22+
from .operations import HttpSuccessOperations, Operations, SelfDefineOperations
2323

2424
if TYPE_CHECKING:
2525
from azure.core import AzureClouds
@@ -31,6 +31,10 @@ class PyprojectMgmtClient: # pylint: disable=client-accepts-api-version-keyword
3131
3232
:ivar http_success: HttpSuccessOperations operations
3333
:vartype http_success: azure.mgmt.pyproject.operations.HttpSuccessOperations
34+
:ivar operations: Operations operations
35+
:vartype operations: azure.mgmt.pyproject.operations.Operations
36+
:ivar self_define: SelfDefineOperations operations
37+
:vartype self_define: azure.mgmt.pyproject.operations.SelfDefineOperations
3438
:param credential: Credential needed for the client to connect to Azure. Required.
3539
:type credential: ~azure.core.credentials.TokenCredential
3640
:param base_url: Service URL. Default value is None.
@@ -82,6 +86,8 @@ def __init__(
8286
self._deserialize = Deserializer(client_models)
8387
self._serialize.client_side_validation = False
8488
self.http_success = HttpSuccessOperations(self._client, self._config, self._serialize, self._deserialize)
89+
self.operations = Operations(self._client, self._config, self._serialize, self._deserialize)
90+
self.self_define = SelfDefineOperations(self._client, self._config, self._serialize, self._deserialize)
8591

8692
def _send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
8793
"""Runs the network request through the client's chained policies.

packages/autorest.python/samples/specification/azure-mgmt-pyproject/test/azure-mgmt-pyproject/azure/mgmt/pyproject/aio/_pyproject_mgmt_client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from .._utils.serialization import Deserializer, Serializer
2121
from ._configuration import PyprojectMgmtClientConfiguration
22-
from .operations import HttpSuccessOperations
22+
from .operations import HttpSuccessOperations, Operations, SelfDefineOperations
2323

2424
if TYPE_CHECKING:
2525
from azure.core import AzureClouds
@@ -31,6 +31,10 @@ class PyprojectMgmtClient: # pylint: disable=client-accepts-api-version-keyword
3131
3232
:ivar http_success: HttpSuccessOperations operations
3333
:vartype http_success: azure.mgmt.pyproject.aio.operations.HttpSuccessOperations
34+
:ivar operations: Operations operations
35+
:vartype operations: azure.mgmt.pyproject.aio.operations.Operations
36+
:ivar self_define: SelfDefineOperations operations
37+
:vartype self_define: azure.mgmt.pyproject.aio.operations.SelfDefineOperations
3438
:param credential: Credential needed for the client to connect to Azure. Required.
3539
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
3640
:param base_url: Service URL. Default value is None.
@@ -84,6 +88,8 @@ def __init__(
8488
self._deserialize = Deserializer(client_models)
8589
self._serialize.client_side_validation = False
8690
self.http_success = HttpSuccessOperations(self._client, self._config, self._serialize, self._deserialize)
91+
self.operations = Operations(self._client, self._config, self._serialize, self._deserialize)
92+
self.self_define = SelfDefineOperations(self._client, self._config, self._serialize, self._deserialize)
8793

8894
def _send_request(
8995
self, request: HttpRequest, *, stream: bool = False, **kwargs: Any

packages/autorest.python/samples/specification/azure-mgmt-pyproject/test/azure-mgmt-pyproject/azure/mgmt/pyproject/aio/operations/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@
1313
from ._patch import * # pylint: disable=unused-wildcard-import
1414

1515
from ._http_success_operations import HttpSuccessOperations # type: ignore
16+
from ._operations import Operations # type: ignore
17+
from ._self_define_operations import SelfDefineOperations # type: ignore
1618

1719
from ._patch import __all__ as _patch_all
1820
from ._patch import *
1921
from ._patch import patch_sdk as _patch_sdk
2022

2123
__all__ = [
2224
"HttpSuccessOperations",
25+
"Operations",
26+
"SelfDefineOperations",
2327
]
2428
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
2529
_patch_sdk()

packages/autorest.python/samples/specification/azure-mgmt-pyproject/test/azure-mgmt-pyproject/azure/mgmt/pyproject/aio/operations/_http_success_operations.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
T = TypeVar("T")
3030
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any]]
31+
List = list
3132

3233

3334
class HttpSuccessOperations:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
from collections.abc import MutableMapping
9+
from io import IOBase
10+
from typing import Any, Callable, IO, Optional, TypeVar, Union, overload
11+
12+
from azure.core import AsyncPipelineClient
13+
from azure.core.exceptions import (
14+
ClientAuthenticationError,
15+
HttpResponseError,
16+
ResourceExistsError,
17+
ResourceNotFoundError,
18+
ResourceNotModifiedError,
19+
map_error,
20+
)
21+
from azure.core.pipeline import PipelineResponse
22+
from azure.core.rest import AsyncHttpResponse, HttpRequest
23+
from azure.core.tracing.decorator_async import distributed_trace_async
24+
from azure.core.utils import case_insensitive_dict
25+
from azure.mgmt.core.exceptions import ARMErrorFormat
26+
27+
from ..._utils.serialization import Deserializer, Serializer
28+
from ...operations._operations import build_list_request
29+
from .._configuration import PyprojectMgmtClientConfiguration
30+
31+
T = TypeVar("T")
32+
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, dict[str, Any]], Any]]
33+
List = list
34+
35+
36+
class Operations:
37+
"""
38+
.. warning::
39+
**DO NOT** instantiate this class directly.
40+
41+
Instead, you should access the following operations through
42+
:class:`~azure.mgmt.pyproject.aio.PyprojectMgmtClient`'s
43+
:attr:`operations` attribute.
44+
"""
45+
46+
def __init__(self, *args, **kwargs) -> None:
47+
input_args = list(args)
48+
self._client: AsyncPipelineClient = input_args.pop(0) if input_args else kwargs.pop("client")
49+
self._config: PyprojectMgmtClientConfiguration = input_args.pop(0) if input_args else kwargs.pop("config")
50+
self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer")
51+
self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer")
52+
53+
@overload
54+
async def list(self, body: List[str], *, content_type: str = "application/json", **kwargs: Any) -> None:
55+
"""Process list of strings.
56+
57+
Processes a list of strings with no return value.
58+
59+
:param body: List of strings to process. Required.
60+
:type body: list[str]
61+
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
62+
Default value is "application/json".
63+
:paramtype content_type: str
64+
:return: None or the result of cls(response)
65+
:rtype: None
66+
:raises ~azure.core.exceptions.HttpResponseError:
67+
"""
68+
69+
@overload
70+
async def list(self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any) -> None:
71+
"""Process list of strings.
72+
73+
Processes a list of strings with no return value.
74+
75+
:param body: List of strings to process. Required.
76+
:type body: IO[bytes]
77+
:keyword content_type: Body Parameter content-type. Content type parameter for binary body.
78+
Default value is "application/json".
79+
:paramtype content_type: str
80+
:return: None or the result of cls(response)
81+
:rtype: None
82+
:raises ~azure.core.exceptions.HttpResponseError:
83+
"""
84+
85+
@distributed_trace_async
86+
async def list(self, body: Union[List[str], IO[bytes]], **kwargs: Any) -> None:
87+
"""Process list of strings.
88+
89+
Processes a list of strings with no return value.
90+
91+
:param body: List of strings to process. Is either a [str] type or a IO[bytes] type. Required.
92+
:type body: list[str] or IO[bytes]
93+
:return: None or the result of cls(response)
94+
:rtype: None
95+
:raises ~azure.core.exceptions.HttpResponseError:
96+
"""
97+
error_map: MutableMapping = {
98+
401: ClientAuthenticationError,
99+
404: ResourceNotFoundError,
100+
409: ResourceExistsError,
101+
304: ResourceNotModifiedError,
102+
}
103+
error_map.update(kwargs.pop("error_map", {}) or {})
104+
105+
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
106+
_params = kwargs.pop("params", {}) or {}
107+
108+
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
109+
cls: ClsType[None] = kwargs.pop("cls", None)
110+
111+
content_type = content_type or "application/json"
112+
_json = None
113+
_content = None
114+
if isinstance(body, (IOBase, bytes)):
115+
_content = body
116+
else:
117+
_json = self._serialize.body(body, "[str]")
118+
119+
_request = build_list_request(
120+
content_type=content_type,
121+
json=_json,
122+
content=_content,
123+
headers=_headers,
124+
params=_params,
125+
)
126+
_request.url = self._client.format_url(_request.url)
127+
128+
_stream = False
129+
pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access
130+
_request, stream=_stream, **kwargs
131+
)
132+
133+
response = pipeline_response.http_response
134+
135+
if response.status_code not in [204]:
136+
map_error(status_code=response.status_code, response=response, error_map=error_map)
137+
raise HttpResponseError(response=response, error_format=ARMErrorFormat)
138+
139+
if cls:
140+
return cls(pipeline_response, None, {}) # type: ignore

0 commit comments

Comments
 (0)