Skip to content

Commit bd88e45

Browse files
Fix codegen crashes for intersection types and complex list inner types (#172)
Why === Codegen fails when a schema contains intersection types (`allOf`) or lists with complex inner types (e.g. `list[dict[str, Any]]`). Both crash with `Complex type must be put through render_type_expr!` or `Unexpected expression when expecting a type name: DictTypeExpr(...)` because `TypeName` objects are used directly in f-strings or passed to `ensure_literal_type` which only accepts simple `TypeName` values. What changed ============ - Fix `TypeName.__str__()` crash in the `RiverIntersectionType` encoder by wrapping `encoder_name` with `render_literal_type()`, matching the existing pattern used by `RiverUnionType` (line 625) and `RiverConcreteType` (line 654) - Fix `ensure_literal_type` crash when a list's inner type is a complex expression (e.g. `list[dict[str, Any]]`) by guarding the `ListTypeExpr` match to only enter the encoding branch for `TypeName` inner types, falling through to `list(x)` for composite types that don't need encoding Test plan ========= _Describe what you did to test this change to a level of detail that allows your reviewer to test it_
1 parent f216da6 commit bd88e45

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/replit_river/codegen/client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,9 @@ def {_field_name}(
407407
encoder_parts.append(("isinstance(x, str)", "x"))
408408
elif t.type == "array":
409409
match type_name:
410-
case ListTypeExpr(inner_type_name):
410+
case ListTypeExpr(inner_type_name) if isinstance(
411+
inner_type_name, TypeName
412+
):
411413
# Primitives don't need encoding
412414
inner_type_str = render_literal_type(inner_type_name)
413415
if inner_type_str in ("str", "int", "float", "bool", "Any"):
@@ -633,7 +635,9 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
633635
f"encode_{render_literal_type(type_name)}"
634636
)
635637
encoder_names.add(encoder_name)
636-
typeddict_encoder.append(f"{encoder_name}(x[{repr(name)}])")
638+
typeddict_encoder.append(
639+
f"{render_literal_type(encoder_name)}(x[{repr(name)}])"
640+
)
637641
elif isinstance(prop, RiverConcreteType):
638642
if name == "$kind":
639643
safe_name = "kind"

0 commit comments

Comments
 (0)