@typespec/http-client-python 0.14.0 → 0.14.1-dev.2

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.
@@ -1,4 +1,4 @@
1
1
  import { defineConfig, mergeConfig } from "vitest/config";
2
- import { defaultTypeSpecVitestConfig } from "../../../vitest.workspace.js";
2
+ import { defaultTypeSpecVitestConfig } from "../../../vitest.config.js";
3
3
 
4
4
  export default mergeConfig(defaultTypeSpecVitestConfig, defineConfig({}));
@@ -322,13 +322,11 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
322
322
  )
323
323
  serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
324
324
  for og in self.operation_groups:
325
- suffix = f".{og.filename}" if (not self.code_model.options["multiapi"]) and og.is_mixin else ""
326
325
  file_import.add_submodule_import(
327
326
  self.code_model.get_relative_import_path(
328
327
  serialize_namespace,
329
328
  self.code_model.get_imported_namespace_for_operation(og.client_namespace, async_mode),
330
- )
331
- + suffix,
329
+ ),
332
330
  og.class_name,
333
331
  ImportType.LOCAL,
334
332
  )
@@ -19,14 +19,14 @@ from .base_serializer import BaseSerializer
19
19
  VERSION_MAP = {
20
20
  "msrest": "0.7.1",
21
21
  "isodate": "0.6.1",
22
- "azure-mgmt-core": "1.5.0",
23
- "azure-core": "1.30.0",
22
+ "azure-mgmt-core": "1.6.0",
23
+ "azure-core": "1.35.0",
24
24
  "typing-extensions": "4.6.0",
25
25
  "corehttp": "1.0.0b6",
26
26
  }
27
27
 
28
28
  MIN_PYTHON_VERSION = "3.9"
29
- MAX_PYTHON_VERSION = "3.12"
29
+ MAX_PYTHON_VERSION = "3.13"
30
30
 
31
31
 
32
32
  class GeneralSerializer(BaseSerializer):
@@ -9,6 +9,12 @@ from jinja2 import Environment
9
9
  from ..models import CodeModel, OperationGroup
10
10
 
11
11
 
12
+ def get_pylint_disable(code_model: CodeModel, og: OperationGroup) -> str:
13
+ if og.is_mixin and not code_model.options["multiapi"]:
14
+ return " # pylint: disable=unused-import"
15
+ return ""
16
+
17
+
12
18
  class OperationsInitSerializer:
13
19
  def __init__(
14
20
  self,
@@ -27,9 +33,8 @@ class OperationsInitSerializer:
27
33
  return "_operations" if self.code_model.options["combine-operation-files"] else operation_group.filename
28
34
 
29
35
  return [
30
- f"from .{_get_filename(og)} import {og.class_name} # type: ignore"
36
+ f"from .{_get_filename(og)} import {og.class_name} # type: ignore{get_pylint_disable(self.code_model, og)}"
31
37
  for og in self.operation_groups
32
- if not og.is_mixin or self.code_model.options["multiapi"]
33
38
  ]
34
39
 
35
40
  def serialize(self) -> str:
@@ -69,7 +69,7 @@ class SampleSerializer(BaseSerializer):
69
69
  def _client_params(self) -> Dict[str, Any]:
70
70
  # client params
71
71
  special_param = {}
72
- credential_type = getattr(self.code_model.clients[0].credential, "type", None)
72
+ credential_type = getattr(self.operation_group.client.credential, "type", None)
73
73
  if isinstance(credential_type, TokenCredentialType):
74
74
  special_param.update({"credential": "DefaultAzureCredential()"})
75
75
  elif isinstance(credential_type, KeyCredentialType):
@@ -78,7 +78,7 @@ class SampleSerializer(BaseSerializer):
78
78
  params = [
79
79
  p
80
80
  for p in (
81
- self.code_model.clients[0].parameters.positional + self.code_model.clients[0].parameters.keyword_only
81
+ self.operation_group.client.parameters.positional + self.operation_group.client.parameters.keyword_only
82
82
  )
83
83
  if not p.optional and p.client_default_value is None
84
84
  ]
@@ -153,6 +153,7 @@ class SampleSerializer(BaseSerializer):
153
153
  operation_result, return_var = self._operation_result()
154
154
  return self.env.get_template("sample.py.jinja2").render(
155
155
  code_model=self.code_model,
156
+ client=self.operation_group.client,
156
157
  file_name=self.file_name,
157
158
  operation_result=operation_result,
158
159
  operation_params=self._operation_params(),
@@ -27,7 +27,7 @@
27
27
  {% endif %}
28
28
  """
29
29
  def main():
30
- client = {{ code_model.clients[0].name }}(
30
+ client = {{ client.name }}(
31
31
  {% for key,value in client_params.items() %}
32
32
  {{ key }}={{ value }},
33
33
  {% endfor %}
@@ -97,7 +97,7 @@ _always_reserved = [
97
97
  "int",
98
98
  ]
99
99
 
100
- RESERVED_MODEL_PROPERTIES = [
100
+ RESERVED_TSP_MODEL_PROPERTIES = [
101
101
  "keys",
102
102
  "items",
103
103
  "values",
@@ -109,6 +109,8 @@ RESERVED_MODEL_PROPERTIES = [
109
109
  "get",
110
110
  "copy",
111
111
  "as_dict",
112
+ # following are reserved special words for TSP models
113
+ "datetime",
112
114
  ]
113
115
 
114
116
  RESERVED_WORDS = {
@@ -187,7 +189,7 @@ RESERVED_WORDS = {
187
189
 
188
190
  TSP_RESERVED_WORDS = {
189
191
  PadType.PARAMETER: ["stream"],
190
- PadType.PROPERTY: RESERVED_MODEL_PROPERTIES,
192
+ PadType.PROPERTY: RESERVED_TSP_MODEL_PROPERTIES,
191
193
  }
192
194
 
193
195
  REDEFINED_BUILTINS = [ # we don't pad, but we need to do lint ignores
@@ -322,13 +322,11 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=t
322
322
  )
323
323
  serialize_namespace = kwargs.get("serialize_namespace", self.code_model.namespace)
324
324
  for og in self.operation_groups:
325
- suffix = f".{og.filename}" if (not self.code_model.options["multiapi"]) and og.is_mixin else ""
326
325
  file_import.add_submodule_import(
327
326
  self.code_model.get_relative_import_path(
328
327
  serialize_namespace,
329
328
  self.code_model.get_imported_namespace_for_operation(og.client_namespace, async_mode),
330
- )
331
- + suffix,
329
+ ),
332
330
  og.class_name,
333
331
  ImportType.LOCAL,
334
332
  )
@@ -19,14 +19,14 @@ from .base_serializer import BaseSerializer
19
19
  VERSION_MAP = {
20
20
  "msrest": "0.7.1",
21
21
  "isodate": "0.6.1",
22
- "azure-mgmt-core": "1.5.0",
23
- "azure-core": "1.30.0",
22
+ "azure-mgmt-core": "1.6.0",
23
+ "azure-core": "1.35.0",
24
24
  "typing-extensions": "4.6.0",
25
25
  "corehttp": "1.0.0b6",
26
26
  }
27
27
 
28
28
  MIN_PYTHON_VERSION = "3.9"
29
- MAX_PYTHON_VERSION = "3.12"
29
+ MAX_PYTHON_VERSION = "3.13"
30
30
 
31
31
 
32
32
  class GeneralSerializer(BaseSerializer):
@@ -9,6 +9,12 @@ from jinja2 import Environment
9
9
  from ..models import CodeModel, OperationGroup
10
10
 
11
11
 
12
+ def get_pylint_disable(code_model: CodeModel, og: OperationGroup) -> str:
13
+ if og.is_mixin and not code_model.options["multiapi"]:
14
+ return " # pylint: disable=unused-import"
15
+ return ""
16
+
17
+
12
18
  class OperationsInitSerializer:
13
19
  def __init__(
14
20
  self,
@@ -27,9 +33,8 @@ class OperationsInitSerializer:
27
33
  return "_operations" if self.code_model.options["combine-operation-files"] else operation_group.filename
28
34
 
29
35
  return [
30
- f"from .{_get_filename(og)} import {og.class_name} # type: ignore"
36
+ f"from .{_get_filename(og)} import {og.class_name} # type: ignore{get_pylint_disable(self.code_model, og)}"
31
37
  for og in self.operation_groups
32
- if not og.is_mixin or self.code_model.options["multiapi"]
33
38
  ]
34
39
 
35
40
  def serialize(self) -> str:
@@ -69,7 +69,7 @@ class SampleSerializer(BaseSerializer):
69
69
  def _client_params(self) -> Dict[str, Any]:
70
70
  # client params
71
71
  special_param = {}
72
- credential_type = getattr(self.code_model.clients[0].credential, "type", None)
72
+ credential_type = getattr(self.operation_group.client.credential, "type", None)
73
73
  if isinstance(credential_type, TokenCredentialType):
74
74
  special_param.update({"credential": "DefaultAzureCredential()"})
75
75
  elif isinstance(credential_type, KeyCredentialType):
@@ -78,7 +78,7 @@ class SampleSerializer(BaseSerializer):
78
78
  params = [
79
79
  p
80
80
  for p in (
81
- self.code_model.clients[0].parameters.positional + self.code_model.clients[0].parameters.keyword_only
81
+ self.operation_group.client.parameters.positional + self.operation_group.client.parameters.keyword_only
82
82
  )
83
83
  if not p.optional and p.client_default_value is None
84
84
  ]
@@ -153,6 +153,7 @@ class SampleSerializer(BaseSerializer):
153
153
  operation_result, return_var = self._operation_result()
154
154
  return self.env.get_template("sample.py.jinja2").render(
155
155
  code_model=self.code_model,
156
+ client=self.operation_group.client,
156
157
  file_name=self.file_name,
157
158
  operation_result=operation_result,
158
159
  operation_params=self._operation_params(),
@@ -27,7 +27,7 @@
27
27
  {% endif %}
28
28
  """
29
29
  def main():
30
- client = {{ code_model.clients[0].name }}(
30
+ client = {{ client.name }}(
31
31
  {% for key,value in client_params.items() %}
32
32
  {{ key }}={{ value }},
33
33
  {% endfor %}
@@ -97,7 +97,7 @@ _always_reserved = [
97
97
  "int",
98
98
  ]
99
99
 
100
- RESERVED_MODEL_PROPERTIES = [
100
+ RESERVED_TSP_MODEL_PROPERTIES = [
101
101
  "keys",
102
102
  "items",
103
103
  "values",
@@ -109,6 +109,8 @@ RESERVED_MODEL_PROPERTIES = [
109
109
  "get",
110
110
  "copy",
111
111
  "as_dict",
112
+ # following are reserved special words for TSP models
113
+ "datetime",
112
114
  ]
113
115
 
114
116
  RESERVED_WORDS = {
@@ -187,7 +189,7 @@ RESERVED_WORDS = {
187
189
 
188
190
  TSP_RESERVED_WORDS = {
189
191
  PadType.PARAMETER: ["stream"],
190
- PadType.PROPERTY: RESERVED_MODEL_PROPERTIES,
192
+ PadType.PROPERTY: RESERVED_TSP_MODEL_PROPERTIES,
191
193
  }
192
194
 
193
195
  REDEFINED_BUILTINS = [ # we don't pad, but we need to do lint ignores
@@ -3,6 +3,7 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
+ import inspect
6
7
  import pytest
7
8
  from specs.azure.clientgenerator.core.override.aio import OverrideClient
8
9
 
@@ -21,3 +22,22 @@ async def test_reorder_parameters(client: OverrideClient):
21
22
  @pytest.mark.asyncio
22
23
  async def test_group_parameters(client: OverrideClient):
23
24
  await client.group_parameters.group(param1="param1", param2="param2")
25
+
26
+
27
+ def test_reorder_parameters_unit_async(client: OverrideClient):
28
+ # make sure signature name of `reorder_parameters` are ["param1", "param2"]
29
+ # Get the reorder method from the reorder_parameters operation
30
+ reorder_method = client.reorder_parameters.reorder
31
+
32
+ # Inspect the method signature
33
+ sig = inspect.signature(reorder_method)
34
+
35
+ # Get parameter names excluding 'self' and '**kwargs'
36
+ param_names = [
37
+ param_name
38
+ for param_name, param in sig.parameters.items()
39
+ if param_name not in ("self", "kwargs") and param.kind != param.VAR_KEYWORD
40
+ ]
41
+
42
+ # Assert that the parameter names are exactly ["param1", "param2"]
43
+ assert param_names == ["param1", "param2"], f"Expected parameter names ['param1', 'param2'], but got {param_names}"
@@ -3,6 +3,7 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
+ import inspect
6
7
  import pytest
7
8
  from specs.azure.clientgenerator.core.override import OverrideClient
8
9
 
@@ -19,3 +20,22 @@ def test_reorder_parameters(client: OverrideClient):
19
20
 
20
21
  def test_group_parameters(client: OverrideClient):
21
22
  client.group_parameters.group(param1="param1", param2="param2")
23
+
24
+
25
+ # make sure signature name of `reorder_parameters` are ["param1", "param2"]
26
+ def test_reorder_parameters_unit(client: OverrideClient):
27
+ # Get the reorder method from the reorder_parameters operation
28
+ reorder_method = client.reorder_parameters.reorder
29
+
30
+ # Inspect the method signature
31
+ sig = inspect.signature(reorder_method)
32
+
33
+ # Get parameter names excluding 'self' and '**kwargs'
34
+ param_names = [
35
+ param_name
36
+ for param_name, param in sig.parameters.items()
37
+ if param_name not in ("self", "kwargs") and param.kind != param.VAR_KEYWORD
38
+ ]
39
+
40
+ # Assert that the parameter names are exactly ["param1", "param2"]
41
+ assert param_names == ["param1", "param2"], f"Expected parameter names ['param1', 'param2'], but got {param_names}"
@@ -1,6 +1,6 @@
1
1
  -r ../dev_requirements.txt
2
2
  -e ../../
3
- azure-mgmt-core==1.5.0
3
+ azure-mgmt-core==1.6.0
4
4
 
5
5
  # only for azure
6
6
  -e ./generated/azure-client-generator-core-access
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/http-client-python",
3
- "version": "0.14.0",
3
+ "version": "0.14.1-dev.2",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec emitter for Python SDKs",
6
6
  "homepage": "https://typespec.io",