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