Skip to content

Commit a130bfc

Browse files
iscai-msftCopilot
andcommitted
fix: use TypedDict dicts instead of model classes in naming test
The typeddict test should pass plain dicts with wire names, not model class constructors which expect client names. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 48d2aed commit a130bfc

4 files changed

Lines changed: 31 additions & 22 deletions

File tree

packages/http-client-python/eng/scripts/ci/regenerate.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ const SpecialFlags: Record<string, Record<string, any>> = {
6666

6767
// ---- Spec-specific emitter option overrides ----
6868

69-
const AZURE_EMITTER_OPTIONS: Record<
70-
string,
71-
Record<string, string> | Record<string, string>[]
72-
> = {
69+
const AZURE_EMITTER_OPTIONS: Record<string, Record<string, string> | Record<string, string>[]> = {
7370
"azure/client-generator-core/access": {
7471
namespace: "specs.azure.clientgenerator.core.access",
7572
},
@@ -404,10 +401,7 @@ function getEmitterOptions(
404401
return Array.isArray(emitterOpts) ? emitterOpts : [emitterOpts];
405402
}
406403

407-
async function getSubdirectories(
408-
baseDir: string,
409-
flags: RegenerateFlags,
410-
): Promise<string[]> {
404+
async function getSubdirectories(baseDir: string, flags: RegenerateFlags): Promise<string[]> {
411405
const subdirectories: string[] = [];
412406

413407
async function searchDir(currentDir: string) {

packages/http-client-python/generator/pygen/codegen/models/model_type.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ def __init__(
7878
self.usage: int = self.yaml_data.get("usage", UsageFlags.Input.value | UsageFlags.Output.value)
7979
self.client_namespace: str = self.yaml_data.get("clientNamespace", code_model.namespace)
8080
typed_dict_only_opt = code_model.options.get("typed-dict-only-models", [])
81-
self.is_typed_dict_only: bool = self.yaml_data.get(
82-
"typedDictOnly", False
83-
) or typed_dict_only_opt == "all" or self.name in typed_dict_only_opt
81+
self.is_typed_dict_only: bool = (
82+
self.yaml_data.get("typedDictOnly", False)
83+
or typed_dict_only_opt == "all"
84+
or self.name in typed_dict_only_opt
85+
)
8486

8587
@property
8688
def is_usage_output(self) -> bool:

packages/http-client-python/generator/pygen/codegen/serializers/types_serializer.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,25 @@
1717
# Python builtin type names that can be shadowed by TypedDict field wire_names.
1818
# When a field name matches one of these, all references to that builtin in type
1919
# annotations within the same class are qualified as builtins.X.
20-
_BUILTIN_TYPE_NAMES = frozenset({
21-
"int", "str", "float", "bool", "list", "dict", "tuple", "set",
22-
"bytes", "type", "object", "complex", "frozenset", "bytearray", "memoryview",
23-
})
20+
_BUILTIN_TYPE_NAMES = frozenset(
21+
{
22+
"int",
23+
"str",
24+
"float",
25+
"bool",
26+
"list",
27+
"dict",
28+
"tuple",
29+
"set",
30+
"bytes",
31+
"type",
32+
"object",
33+
"complex",
34+
"frozenset",
35+
"bytearray",
36+
"memoryview",
37+
}
38+
)
2439

2540

2641
def _qualify_shadowed_builtins(annotation: str, shadowed: frozenset[str]) -> str:

packages/http-client-python/tests/mock_api/azure/test_client_naming_typeddict.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,17 @@ def client():
1515

1616
def test_client(client: NamingClient):
1717
"""TypedDict uses wire name 'defaultName', not client name 'client_name'."""
18-
client.property.client(models.ClientNameModel(defaultName=True))
18+
client.property.client({"defaultName": True})
1919

2020

2121
def test_language(client: NamingClient):
2222
"""TypedDict uses wire name 'defaultName', not language-specific name 'python_name'."""
23-
client.property.language(models.LanguageClientNameModel(defaultName=True))
23+
client.property.language({"defaultName": True})
2424

2525

2626
def test_compatible_with_encoded_name(client: NamingClient):
2727
"""TypedDict uses encoded wire name 'wireName', not client name 'client_name'."""
28-
client.property.compatible_with_encoded_name(
29-
models.ClientNameAndJsonEncodedNameModel(wireName=True)
30-
)
28+
client.property.compatible_with_encoded_name({"wireName": True})
3129

3230

3331
def test_operation(client: NamingClient):
@@ -48,12 +46,12 @@ def test_header_response(client: NamingClient):
4846

4947
def test_model_client(client: NamingClient):
5048
"""TypedDict uses wire name 'defaultName', not client name 'default_name'."""
51-
client.model_client.client(models.ClientModel(defaultName=True))
49+
client.model_client.client({"defaultName": True})
5250

5351

5452
def test_model_language(client: NamingClient):
5553
"""TypedDict uses wire name 'defaultName', not client name 'default_name'."""
56-
client.model_client.language(models.PythonModel(defaultName=True))
54+
client.model_client.language({"defaultName": True})
5755

5856

5957
def test_union_enum_member_name(client: NamingClient):

0 commit comments

Comments
 (0)