From ca8b9473abef3615b429042b9cb4371d8f286edc Mon Sep 17 00:00:00 2001 From: lhchavez Date: Fri, 11 Apr 2025 00:56:56 +0000 Subject: [PATCH] [pid2] Allow optional arrays We have optional arrays, and it would be real neat if we could codegen them. This change codegens them. --- src/replit_river/codegen/client.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/replit_river/codegen/client.py b/src/replit_river/codegen/client.py index f04b5427..9115b64f 100644 --- a/src/replit_river/codegen/client.py +++ b/src/replit_river/codegen/client.py @@ -631,6 +631,16 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]: """.rstrip() ) ) + if name not in prop.required: + typeddict_encoder.append( + dedent( + f""" + if {repr(name)} in x + and x[{repr(name)}] is not None + else None + """ + ) + ) else: if name in prop.required: typeddict_encoder.append(f"x[{repr(safe_name)}]")