Skip to content

Commit ae375eb

Browse files
authored
[codegen] Allow optional arrays (#151)
Why === We have optional arrays, and it would be real neat if we could codegen them. What changed ============ This change codegens them. Test plan ========= https://github.com/replit/ai-infra/actions/runs/14393070588/job/40363959208 doesn't fail again.
1 parent ff13eeb commit ae375eb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/replit_river/codegen/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,16 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
631631
""".rstrip()
632632
)
633633
)
634+
if name not in prop.required:
635+
typeddict_encoder.append(
636+
dedent(
637+
f"""
638+
if {repr(name)} in x
639+
and x[{repr(name)}] is not None
640+
else None
641+
"""
642+
)
643+
)
634644
else:
635645
if name in prop.required:
636646
typeddict_encoder.append(f"x[{repr(safe_name)}]")

0 commit comments

Comments
 (0)