Skip to content

Commit ca8b947

Browse files
committed
[pid2] Allow optional arrays
We have optional arrays, and it would be real neat if we could codegen them. This change codegens them.
1 parent ff13eeb commit ca8b947

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)