feat/stubgen: fix pun field typing error
This commit is contained in:
@@ -60,14 +60,9 @@ def generate_struct(
|
||||
non_union_fields.append((field_name, field_type_str))
|
||||
|
||||
elif "group" in field:
|
||||
group_type_id = type_id_to_int(field["group"]["typeId"])
|
||||
group_info = registry.get(group_type_id)
|
||||
if group_info is not None:
|
||||
type_str = group_info.scoped_name
|
||||
if disc_value != _NO_DISCRIMINANT:
|
||||
union_fields.append((field_name, type_str))
|
||||
else:
|
||||
non_union_fields.append((field_name, type_str))
|
||||
# Groups become inner classes — skip field annotation
|
||||
# (the group class serves as both type and accessor)
|
||||
pass
|
||||
|
||||
# ── class: main type ───────────────────────────────────────────────
|
||||
# Generic type: generate TypeVars and Generic[T] base
|
||||
@@ -225,7 +220,6 @@ def _generate_union_methods(
|
||||
emitter: Emitter, union_fields: list[tuple[str, str]],
|
||||
) -> None:
|
||||
emitter.add_typing_import("Literal")
|
||||
emitter.add_typing_import("overload")
|
||||
|
||||
literal_values = ", ".join(f'"{name}"' for name, _ in union_fields)
|
||||
emitter.add_method(
|
||||
@@ -233,8 +227,12 @@ def _generate_union_methods(
|
||||
return_type=f"Literal[{literal_values}]",
|
||||
)
|
||||
|
||||
if len(union_fields) > 1:
|
||||
emitter.add_typing_import("overload")
|
||||
|
||||
for field_name, type_str in union_fields:
|
||||
emitter.add_decorator("overload")
|
||||
if len(union_fields) > 1:
|
||||
emitter.add_decorator("overload")
|
||||
emitter.add_method(
|
||||
"init",
|
||||
params=["self", f'name: Literal["{field_name}"]'],
|
||||
|
||||
@@ -197,8 +197,6 @@ def _resolve_cross_imports(
|
||||
break
|
||||
|
||||
all_imports.append(tname)
|
||||
if ref_info and ref_info.kind == "struct":
|
||||
all_imports.extend([f"{tname}Builder", f"{tname}Reader"])
|
||||
|
||||
emitter.add_import(
|
||||
f"from .{module_name} import {', '.join(all_imports)}"
|
||||
|
||||
Reference in New Issue
Block a user