@typespec/http-client-python 0.14.0 → 0.14.1-dev.1
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.
- package/emitter/vitest.config.ts +1 -1
- package/eng/scripts/setup/__pycache__/package_manager.cpython-39.pyc +0 -0
- package/eng/scripts/setup/__pycache__/venvtools.cpython-39.pyc +0 -0
- package/generator/build/lib/pygen/codegen/models/client.py +1 -3
- package/generator/build/lib/pygen/codegen/serializers/general_serializer.py +1 -1
- package/generator/build/lib/pygen/codegen/serializers/operations_init_serializer.py +7 -2
- package/generator/build/lib/pygen/codegen/serializers/sample_serializer.py +3 -2
- package/generator/build/lib/pygen/codegen/templates/sample.py.jinja2 +1 -1
- package/generator/build/lib/pygen/preprocess/python_mappings.py +4 -2
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/codegen/models/client.py +1 -3
- package/generator/pygen/codegen/serializers/general_serializer.py +1 -1
- package/generator/pygen/codegen/serializers/operations_init_serializer.py +7 -2
- package/generator/pygen/codegen/serializers/sample_serializer.py +3 -2
- package/generator/pygen/codegen/templates/sample.py.jinja2 +1 -1
- package/generator/pygen/preprocess/python_mappings.py +4 -2
- package/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_override_async.py +20 -0
- package/generator/test/azure/mock_api_tests/test_azure_client_generator_core_override.py +20 -0
- package/package.json +1 -1
package/emitter/vitest.config.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { defineConfig, mergeConfig } from "vitest/config";
|
|
2
|
-
import { defaultTypeSpecVitestConfig } from "../../../vitest.
|
|
2
|
+
import { defaultTypeSpecVitestConfig } from "../../../vitest.config.js";
|
|
3
3
|
|
|
4
4
|
export default mergeConfig(defaultTypeSpecVitestConfig, defineConfig({}));
|
|
Binary file
|
|
Binary file
|
|
@@ -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
|
)
|
|
@@ -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}
|
|
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.
|
|
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.
|
|
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(),
|
|
@@ -97,7 +97,7 @@ _always_reserved = [
|
|
|
97
97
|
"int",
|
|
98
98
|
]
|
|
99
99
|
|
|
100
|
-
|
|
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:
|
|
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
|
|
Binary file
|
|
@@ -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
|
)
|
|
@@ -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}
|
|
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.
|
|
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.
|
|
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(),
|
|
@@ -97,7 +97,7 @@ _always_reserved = [
|
|
|
97
97
|
"int",
|
|
98
98
|
]
|
|
99
99
|
|
|
100
|
-
|
|
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:
|
|
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}"
|