@typespec/http-client-python 0.11.1 → 0.11.3

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.
Files changed (27) hide show
  1. package/dist/emitter/emitter.js +21 -1
  2. package/dist/emitter/emitter.js.map +1 -1
  3. package/dist/emitter/http.d.ts.map +1 -1
  4. package/dist/emitter/http.js +13 -0
  5. package/dist/emitter/http.js.map +1 -1
  6. package/emitter/src/emitter.ts +21 -1
  7. package/emitter/src/http.ts +13 -0
  8. package/emitter/temp/tsconfig.tsbuildinfo +1 -1
  9. package/eng/scripts/ci/mypy.ini +4 -1
  10. package/eng/scripts/ci/regenerate.ts +15 -7
  11. package/eng/scripts/ci/run_pyright.py +4 -0
  12. package/eng/scripts/setup/__pycache__/venvtools.cpython-39.pyc +0 -0
  13. package/generator/build/lib/pygen/codegen/models/operation_group.py +13 -1
  14. package/generator/build/lib/pygen/codegen/models/paging_operation.py +4 -0
  15. package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +11 -0
  16. package/generator/build/lib/pygen/codegen/templates/operation_group.py.jinja2 +2 -2
  17. package/generator/build/lib/pygen/codegen/templates/operation_groups_container.py.jinja2 +0 -1
  18. package/generator/component-detection-pip-report.json +8 -13
  19. package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
  20. package/generator/pygen/codegen/models/operation_group.py +13 -1
  21. package/generator/pygen/codegen/models/paging_operation.py +4 -0
  22. package/generator/pygen/codegen/serializers/builder_serializer.py +11 -0
  23. package/generator/pygen/codegen/templates/operation_group.py.jinja2 +2 -2
  24. package/generator/pygen/codegen/templates/operation_groups_container.py.jinja2 +0 -1
  25. package/generator/test/azure/mock_api_tests/asynctests/test_azure_core_page_async.py +10 -0
  26. package/generator/test/azure/mock_api_tests/test_azure_core_page.py +9 -0
  27. package/package.json +33 -31
@@ -46,6 +46,9 @@ const AZURE_EMITTER_OPTIONS: Record<string, Record<string, string> | Record<stri
46
46
  "azure/client-generator-core/client-initialization": {
47
47
  namespace: "specs.azure.clientgenerator.core.clientinitialization",
48
48
  },
49
+ "azure/client-generator-core/deserialize-empty-string-as-null": {
50
+ namespace: "specs.azure.clientgenerator.core.emptystring",
51
+ },
49
52
  "azure/client-generator-core/flatten-property": {
50
53
  namespace: "specs.azure.clientgenerator.core.flattenproperty",
51
54
  },
@@ -260,6 +263,7 @@ async function executeCommand(tspCommand: TspCommand): Promise<void> {
260
263
  }
261
264
  const execFileAsync = promisify(execFile);
262
265
  try {
266
+ console.log(chalk.green(`start tsp ${tspCommand.command.join(" ")}`));
263
267
  await execFileAsync("tsp", tspCommand.command, { shell: true });
264
268
  console.log(chalk.green(`tsp ${tspCommand.command.join(" ")} succeeded`));
265
269
  } catch (err) {
@@ -401,16 +405,20 @@ function _getCmdList(spec: string, flags: RegenerateFlags): TspCommand[] {
401
405
  }
402
406
 
403
407
  async function runTaskPool(tasks: Array<() => Promise<void>>, poolLimit: number): Promise<void> {
404
- let currentIndex = 0;
405
-
406
- async function worker() {
407
- while (currentIndex < tasks.length) {
408
- const index = currentIndex++;
409
- await tasks[index]();
408
+ async function worker(start: number, end: number) {
409
+ while (start < end) {
410
+ await tasks[start]();
411
+ start++;
410
412
  }
411
413
  }
412
414
 
413
- const workers = new Array(Math.min(poolLimit, tasks.length)).fill(null).map(() => worker());
415
+ const workers = [];
416
+ let start = 0;
417
+ while (start < tasks.length) {
418
+ const end = Math.min(start + poolLimit, tasks.length);
419
+ workers.push((async () => await worker(start, end))());
420
+ start = end;
421
+ }
414
422
  await Promise.all(workers);
415
423
  }
416
424
 
@@ -31,6 +31,10 @@ def _single_dir_pyright(mod):
31
31
  retries = 3
32
32
  while retries:
33
33
  try:
34
+ # After fully support client hierarchy, we can remove this check
35
+ if "azure-client-generator-core-client-initialization" in str(inner_class.absolute()):
36
+ return True
37
+
34
38
  check_output(
35
39
  [
36
40
  sys.executable,
@@ -64,7 +64,9 @@ class OperationGroup(BaseModel):
64
64
  )
65
65
 
66
66
  def base_class(self, async_mode: bool) -> str:
67
- pipeline_client = f"{'Async' if async_mode else ''}PipelineClient"
67
+ pipeline_client = (
68
+ f"{'Async' if async_mode else ''}PipelineClient[HttpRequest, {'Async' if async_mode else ''}HttpResponse]"
69
+ )
68
70
  base_classes: List[str] = []
69
71
  if self.is_mixin:
70
72
  base_classes.append(f"ClientMixinABC[{pipeline_client}, {self.client.name}Configuration]")
@@ -166,6 +168,16 @@ class OperationGroup(BaseModel):
166
168
  "ClientMixinABC",
167
169
  ImportType.LOCAL,
168
170
  )
171
+ file_import.add_submodule_import(
172
+ "rest",
173
+ "HttpRequest",
174
+ ImportType.SDKCORE,
175
+ )
176
+ file_import.add_submodule_import(
177
+ "rest",
178
+ f"{'Async' if async_mode else ''}HttpResponse",
179
+ ImportType.SDKCORE,
180
+ )
169
181
  else:
170
182
  file_import.add_msrest_import(
171
183
  serialize_namespace=kwargs.get("serialize_namespace", self.code_model.namespace),
@@ -16,6 +16,7 @@ from .imports import ImportType, FileImport, TypingSection
16
16
  from .parameter_list import ParameterList
17
17
  from .model_type import ModelType
18
18
  from .list_type import ListType
19
+ from .parameter import Parameter
19
20
 
20
21
  if TYPE_CHECKING:
21
22
  from .code_model import CodeModel
@@ -59,6 +60,9 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
59
60
  self.pager_sync: str = yaml_data.get("pagerSync") or f"{self.code_model.core_library}.paging.ItemPaged"
60
61
  self.pager_async: str = yaml_data.get("pagerAsync") or f"{self.code_model.core_library}.paging.AsyncItemPaged"
61
62
  self.continuation_token: Dict[str, Any] = yaml_data.get("continuationToken", {})
63
+ self.next_link_reinjected_parameters: List[Parameter] = [
64
+ Parameter.from_yaml(p, code_model) for p in yaml_data.get("nextLinkReInjectedParameters", [])
65
+ ]
62
66
 
63
67
  @property
64
68
  def has_continuation_token(self) -> bool:
@@ -1276,6 +1276,17 @@ class _PagingOperationSerializer(_OperationSerializer[PagingOperationType]):
1276
1276
  else api_version_param.full_client_name
1277
1277
  )
1278
1278
  retval.append(f'_next_request_params["api-version"] = {api_version}')
1279
+ if builder.next_link_reinjected_parameters:
1280
+ for param in builder.next_link_reinjected_parameters:
1281
+ if param.location == ParameterLocation.QUERY:
1282
+ retval.extend(
1283
+ self.parameter_serializer.serialize_query_header(
1284
+ param,
1285
+ "next_request_params",
1286
+ self.serializer_name,
1287
+ self.code_model.is_legacy,
1288
+ )
1289
+ )
1279
1290
  query_str = ", params=_next_request_params"
1280
1291
  next_link_str = "urllib.parse.urljoin(next_link, _parsed_next_link.path)"
1281
1292
  except StopIteration:
@@ -29,7 +29,7 @@ class {{ operation_group.class_name }}: {{ operation_group.pylint_disable() }}
29
29
  models = _models
30
30
 
31
31
  {% endif %}
32
- def __init__(self, *args, **kwargs){{ return_none_type_annotation }}:
32
+ def __init__(self, *args, **kwargs) -> None:
33
33
  input_args = list(args)
34
34
  self._client: {{ 'Async' if async_mode else ''}}PipelineClient = input_args.pop(0) if input_args else kwargs.pop("client")
35
35
  self._config: {{ operation_group.client.name }}Configuration = input_args.pop(0) if input_args else kwargs.pop("config")
@@ -48,7 +48,7 @@ class {{ operation_group.class_name }}: {{ operation_group.pylint_disable() }}
48
48
  {{ check_abstract_methods() }}
49
49
  {% elif operation_group.has_abstract_operations %}
50
50
 
51
- def __init__(self){{ return_none_type_annotation }}:
51
+ def __init__(self) -> None:
52
52
  {{ check_abstract_methods() }}
53
53
  {% endif %}
54
54
  {% if operation_group.is_mixin and code_model.options["multiapi"] %}
@@ -1,6 +1,5 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools %}
2
2
  {% set operations_description = "async operations" if async_mode else "operations" %}
3
- {% set return_none_type_annotation = " -> None" if async_mode else "" %}
4
3
  # coding=utf-8
5
4
  {% if code_model.license_header %}
6
5
  {{ code_model.license_header }}
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "version": "1",
3
- "pip_version": "25.0.1",
3
+ "pip_version": "25.1.1",
4
4
  "install": [
5
5
  {
6
6
  "download_info": {
7
- "url": "https://files.pythonhosted.org/packages/cc/ea/d53f2f8897c46a36df085964d07761ea4c2d1f2cf92019693b6742b7aabb/setuptools-79.0.0-py3-none-any.whl",
7
+ "url": "https://files.pythonhosted.org/packages/53/7e/5d8af3317ddbf9519b687bd1c39d8737fde07d97f54df65553faca5cffb1/setuptools-80.3.1-py3-none-any.whl",
8
8
  "archive_info": {
9
- "hash": "sha256=b9ab3a104bedb292323f53797b00864e10e434a3ab3906813a7169e4745b912a",
9
+ "hash": "sha256=ea8e00d7992054c4c592aeb892f6ad51fe1b4d90cc6947cc45c45717c40ec537",
10
10
  "hashes": {
11
- "sha256": "b9ab3a104bedb292323f53797b00864e10e434a3ab3906813a7169e4745b912a"
11
+ "sha256": "ea8e00d7992054c4c592aeb892f6ad51fe1b4d90cc6947cc45c45717c40ec537"
12
12
  }
13
13
  }
14
14
  },
@@ -18,10 +18,7 @@
18
18
  "metadata": {
19
19
  "metadata_version": "2.4",
20
20
  "name": "setuptools",
21
- "version": "79.0.0",
22
- "dynamic": [
23
- "license-file"
24
- ],
21
+ "version": "80.3.1",
25
22
  "summary": "Easily download, build, install, upgrade, and uninstall Python packages",
26
23
  "description_content_type": "text/x-rst",
27
24
  "keywords": [
@@ -33,9 +30,7 @@
33
30
  "management"
34
31
  ],
35
32
  "author_email": "Python Packaging Authority <distutils-sig@python.org>",
36
- "license_file": [
37
- "LICENSE"
38
- ],
33
+ "license_expression": "MIT",
39
34
  "classifier": [
40
35
  "Development Status :: 5 - Production/Stable",
41
36
  "Intended Audience :: Developers",
@@ -125,9 +120,9 @@
125
120
  "implementation_version": "3.9.21",
126
121
  "os_name": "posix",
127
122
  "platform_machine": "x86_64",
128
- "platform_release": "5.15.0-1086-azure",
123
+ "platform_release": "5.15.0-1088-azure",
129
124
  "platform_system": "Linux",
130
- "platform_version": "#95~20.04.1-Ubuntu SMP Thu Mar 27 18:45:17 UTC 2025",
125
+ "platform_version": "#97~20.04.1-Ubuntu SMP Wed Apr 23 13:25:03 UTC 2025",
131
126
  "python_full_version": "3.9.21",
132
127
  "platform_python_implementation": "CPython",
133
128
  "python_version": "3.9",
@@ -64,7 +64,9 @@ class OperationGroup(BaseModel):
64
64
  )
65
65
 
66
66
  def base_class(self, async_mode: bool) -> str:
67
- pipeline_client = f"{'Async' if async_mode else ''}PipelineClient"
67
+ pipeline_client = (
68
+ f"{'Async' if async_mode else ''}PipelineClient[HttpRequest, {'Async' if async_mode else ''}HttpResponse]"
69
+ )
68
70
  base_classes: List[str] = []
69
71
  if self.is_mixin:
70
72
  base_classes.append(f"ClientMixinABC[{pipeline_client}, {self.client.name}Configuration]")
@@ -166,6 +168,16 @@ class OperationGroup(BaseModel):
166
168
  "ClientMixinABC",
167
169
  ImportType.LOCAL,
168
170
  )
171
+ file_import.add_submodule_import(
172
+ "rest",
173
+ "HttpRequest",
174
+ ImportType.SDKCORE,
175
+ )
176
+ file_import.add_submodule_import(
177
+ "rest",
178
+ f"{'Async' if async_mode else ''}HttpResponse",
179
+ ImportType.SDKCORE,
180
+ )
169
181
  else:
170
182
  file_import.add_msrest_import(
171
183
  serialize_namespace=kwargs.get("serialize_namespace", self.code_model.namespace),
@@ -16,6 +16,7 @@ from .imports import ImportType, FileImport, TypingSection
16
16
  from .parameter_list import ParameterList
17
17
  from .model_type import ModelType
18
18
  from .list_type import ListType
19
+ from .parameter import Parameter
19
20
 
20
21
  if TYPE_CHECKING:
21
22
  from .code_model import CodeModel
@@ -59,6 +60,9 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
59
60
  self.pager_sync: str = yaml_data.get("pagerSync") or f"{self.code_model.core_library}.paging.ItemPaged"
60
61
  self.pager_async: str = yaml_data.get("pagerAsync") or f"{self.code_model.core_library}.paging.AsyncItemPaged"
61
62
  self.continuation_token: Dict[str, Any] = yaml_data.get("continuationToken", {})
63
+ self.next_link_reinjected_parameters: List[Parameter] = [
64
+ Parameter.from_yaml(p, code_model) for p in yaml_data.get("nextLinkReInjectedParameters", [])
65
+ ]
62
66
 
63
67
  @property
64
68
  def has_continuation_token(self) -> bool:
@@ -1276,6 +1276,17 @@ class _PagingOperationSerializer(_OperationSerializer[PagingOperationType]):
1276
1276
  else api_version_param.full_client_name
1277
1277
  )
1278
1278
  retval.append(f'_next_request_params["api-version"] = {api_version}')
1279
+ if builder.next_link_reinjected_parameters:
1280
+ for param in builder.next_link_reinjected_parameters:
1281
+ if param.location == ParameterLocation.QUERY:
1282
+ retval.extend(
1283
+ self.parameter_serializer.serialize_query_header(
1284
+ param,
1285
+ "next_request_params",
1286
+ self.serializer_name,
1287
+ self.code_model.is_legacy,
1288
+ )
1289
+ )
1279
1290
  query_str = ", params=_next_request_params"
1280
1291
  next_link_str = "urllib.parse.urljoin(next_link, _parsed_next_link.path)"
1281
1292
  except StopIteration:
@@ -29,7 +29,7 @@ class {{ operation_group.class_name }}: {{ operation_group.pylint_disable() }}
29
29
  models = _models
30
30
 
31
31
  {% endif %}
32
- def __init__(self, *args, **kwargs){{ return_none_type_annotation }}:
32
+ def __init__(self, *args, **kwargs) -> None:
33
33
  input_args = list(args)
34
34
  self._client: {{ 'Async' if async_mode else ''}}PipelineClient = input_args.pop(0) if input_args else kwargs.pop("client")
35
35
  self._config: {{ operation_group.client.name }}Configuration = input_args.pop(0) if input_args else kwargs.pop("config")
@@ -48,7 +48,7 @@ class {{ operation_group.class_name }}: {{ operation_group.pylint_disable() }}
48
48
  {{ check_abstract_methods() }}
49
49
  {% elif operation_group.has_abstract_operations %}
50
50
 
51
- def __init__(self){{ return_none_type_annotation }}:
51
+ def __init__(self) -> None:
52
52
  {{ check_abstract_methods() }}
53
53
  {% endif %}
54
54
  {% if operation_group.is_mixin and code_model.options["multiapi"] %}
@@ -1,6 +1,5 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools %}
2
2
  {% set operations_description = "async operations" if async_mode else "operations" %}
3
- {% set return_none_type_annotation = " -> None" if async_mode else "" %}
4
3
  # coding=utf-8
5
4
  {% if code_model.license_header %}
6
5
  {{ code_model.license_header }}
@@ -56,3 +56,13 @@ async def test_two_models_as_page_item(client: aio.PageClient):
56
56
  result = [item async for item in client.two_models_as_page_item.list_second_item()]
57
57
  assert len(result) == 1
58
58
  assert result[0].name == "Madge"
59
+
60
+
61
+ @pytest.mark.asyncio
62
+ async def test_list_with_parameterized_next_link(client: aio.PageClient):
63
+ result = [item async for item in client.with_parameterized_next_link(select="name", include_pending=True)]
64
+ assert len(result) == 2
65
+ assert result[0].id == 1
66
+ assert result[0].name == "User1"
67
+ assert result[1].id == 2
68
+ assert result[1].name == "User2"
@@ -49,3 +49,12 @@ def test_two_models_as_page_item(client: PageClient):
49
49
  result = list(client.two_models_as_page_item.list_second_item())
50
50
  assert len(result) == 1
51
51
  assert result[0].name == "Madge"
52
+
53
+
54
+ def test_list_with_parameterized_next_link(client: PageClient):
55
+ result = list(client.with_parameterized_next_link(select="name", include_pending=True))
56
+ assert len(result) == 2
57
+ assert result[0].id == 1
58
+ assert result[0].name == "User1"
59
+ assert result[1].id == 2
60
+ assert result[1].name == "User2"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/http-client-python",
3
- "version": "0.11.1",
3
+ "version": "0.11.3",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec emitter for Python SDKs",
6
6
  "homepage": "https://typespec.io",
@@ -54,20 +54,20 @@
54
54
  "emitter"
55
55
  ],
56
56
  "peerDependencies": {
57
- "@azure-tools/typespec-autorest": ">=0.54.0 <1.0.0",
58
- "@azure-tools/typespec-azure-core": ">=0.54.0 <1.0.0",
59
- "@azure-tools/typespec-azure-resource-manager": ">=0.54.0 <1.0.0",
60
- "@azure-tools/typespec-azure-rulesets": ">=0.54.0 <1.0.0",
61
- "@azure-tools/typespec-client-generator-core": ">=0.54.2 <1.0.0",
62
- "@typespec/compiler": "^1.0.0-0",
63
- "@typespec/http": "^1.0.0-0",
64
- "@typespec/openapi": "^1.0.0-0",
65
- "@typespec/rest": ">=0.68.0 <1.0.0",
66
- "@typespec/versioning": ">=0.68.0 <1.0.0",
67
- "@typespec/events": ">=0.68.0 <1.0.0",
68
- "@typespec/sse": ">=0.68.0 <1.0.0",
69
- "@typespec/streams": ">=0.68.0 <1.0.0",
70
- "@typespec/xml": ">=0.68.0 <1.0.0"
57
+ "@azure-tools/typespec-autorest": ">=0.56.0 <1.0.0",
58
+ "@azure-tools/typespec-azure-core": ">=0.56.0 <1.0.0",
59
+ "@azure-tools/typespec-azure-resource-manager": ">=0.56.0 <1.0.0",
60
+ "@azure-tools/typespec-azure-rulesets": ">=0.56.0 <1.0.0",
61
+ "@azure-tools/typespec-client-generator-core": ">=0.56.1 <1.0.0",
62
+ "@typespec/compiler": "^1.0.0",
63
+ "@typespec/http": "^1.0.0",
64
+ "@typespec/openapi": "^1.0.0",
65
+ "@typespec/rest": ">=0.70.0 <1.0.0",
66
+ "@typespec/versioning": ">=0.70.0 <1.0.0",
67
+ "@typespec/events": ">=0.70.0 <1.0.0",
68
+ "@typespec/sse": ">=0.70.0 <1.0.0",
69
+ "@typespec/streams": ">=0.70.0 <1.0.0",
70
+ "@typespec/xml": ">=0.70.0 <1.0.0"
71
71
  },
72
72
  "dependencies": {
73
73
  "js-yaml": "~4.1.0",
@@ -77,22 +77,24 @@
77
77
  "tsx": "~4.19.1"
78
78
  },
79
79
  "devDependencies": {
80
- "@azure-tools/typespec-autorest": "~0.54.0",
81
- "@azure-tools/typespec-azure-core": "~0.54.0",
82
- "@azure-tools/typespec-azure-resource-manager": "~0.54.0",
83
- "@azure-tools/typespec-azure-rulesets": "~0.54.0",
84
- "@azure-tools/typespec-client-generator-core": "~0.54.2",
85
- "@azure-tools/azure-http-specs": "0.1.0-alpha.14",
86
- "@typespec/compiler": "^1.0.0-0",
87
- "@typespec/http": "^1.0.0-0",
88
- "@typespec/openapi": "^1.0.0-0",
89
- "@typespec/rest": "~0.68.0",
90
- "@typespec/versioning": "~0.68.0",
91
- "@typespec/events": "~0.68.0",
92
- "@typespec/sse": "~0.68.0",
93
- "@typespec/streams": "~0.68.0",
94
- "@typespec/xml": "~0.68.0",
95
- "@typespec/http-specs": "0.1.0-alpha.19",
80
+ "@azure-tools/typespec-autorest": "~0.56.0",
81
+ "@azure-tools/typespec-azure-core": "~0.56.0",
82
+ "@azure-tools/typespec-azure-resource-manager": "~0.56.0",
83
+ "@azure-tools/typespec-azure-rulesets": "~0.56.0",
84
+ "@azure-tools/typespec-client-generator-core": "~0.56.1",
85
+ "@azure-tools/azure-http-specs": "0.1.0-alpha.17",
86
+ "@typespec/compiler": "^1.0.0",
87
+ "@typespec/http": "^1.0.0",
88
+ "@typespec/openapi": "^1.0.0",
89
+ "@typespec/rest": "~0.70.0",
90
+ "@typespec/versioning": "~0.70.0",
91
+ "@typespec/events": "~0.70.0",
92
+ "@typespec/spector": "0.1.0-alpha.13",
93
+ "@typespec/spec-api": "0.1.0-alpha.6",
94
+ "@typespec/sse": "~0.70.0",
95
+ "@typespec/streams": "~0.70.0",
96
+ "@typespec/xml": "~0.70.0",
97
+ "@typespec/http-specs": "0.1.0-alpha.22",
96
98
  "@types/js-yaml": "~4.0.5",
97
99
  "@types/node": "~22.13.14",
98
100
  "@types/semver": "7.5.8",