replit-river 0.17.13__py3-none-any.whl → 0.17.14__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- replit_river/codegen/client.py +53 -23
- {replit_river-0.17.13.dist-info → replit_river-0.17.14.dist-info}/METADATA +1 -1
- {replit_river-0.17.13.dist-info → replit_river-0.17.14.dist-info}/RECORD +5 -5
- {replit_river-0.17.13.dist-info → replit_river-0.17.14.dist-info}/WHEEL +0 -0
- {replit_river-0.17.13.dist-info → replit_river-0.17.14.dist-info}/licenses/LICENSE +0 -0
replit_river/codegen/client.py
CHANGED
|
@@ -389,7 +389,8 @@ def encode_type(
|
|
|
389
389
|
type = original_type
|
|
390
390
|
any_of: list[TypeExpression] = []
|
|
391
391
|
|
|
392
|
-
|
|
392
|
+
# Collect (type_check, encoder_expr) pairs for building ternary chain
|
|
393
|
+
encoder_parts: list[tuple[str | None, str]] = []
|
|
393
394
|
for i, t in enumerate(type.anyOf):
|
|
394
395
|
type_name, _, contents, _ = encode_type(
|
|
395
396
|
t,
|
|
@@ -403,34 +404,63 @@ def encode_type(
|
|
|
403
404
|
chunks.extend(contents)
|
|
404
405
|
if isinstance(t, RiverConcreteType):
|
|
405
406
|
if t.type == "string":
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
# TODO(dstewart): This structure changed since we were incorrectly
|
|
409
|
-
# leaking ListTypeExprs into codegen. This generated
|
|
410
|
-
# code is probably wrong.
|
|
407
|
+
encoder_parts.append(("isinstance(x, str)", "x"))
|
|
408
|
+
elif t.type == "array":
|
|
411
409
|
match type_name:
|
|
412
410
|
case ListTypeExpr(inner_type_name):
|
|
413
|
-
|
|
414
|
-
|
|
411
|
+
# Primitives don't need encoding
|
|
412
|
+
inner_type_str = render_literal_type(inner_type_name)
|
|
413
|
+
if inner_type_str in ("str", "int", "float", "bool", "Any"):
|
|
414
|
+
encoder_parts.append(("isinstance(x, list)", "list(x)"))
|
|
415
|
+
else:
|
|
416
|
+
encoder_parts.append(
|
|
417
|
+
(
|
|
418
|
+
"isinstance(x, list)",
|
|
419
|
+
f"[encode_{inner_type_str}(y) for y in x]",
|
|
420
|
+
)
|
|
421
|
+
)
|
|
422
|
+
case _:
|
|
423
|
+
encoder_parts.append(("isinstance(x, list)", "list(x)"))
|
|
424
|
+
elif t.type == "object":
|
|
425
|
+
match type_name:
|
|
426
|
+
case TypeName(value):
|
|
427
|
+
encoder_parts.append(
|
|
428
|
+
("isinstance(x, dict)", f"encode_{value}(x)")
|
|
415
429
|
)
|
|
430
|
+
case _:
|
|
431
|
+
encoder_parts.append(("isinstance(x, dict)", "dict(x)"))
|
|
432
|
+
elif t.type in ("number", "integer"):
|
|
433
|
+
match type_name:
|
|
416
434
|
case LiteralTypeExpr(const):
|
|
417
|
-
|
|
435
|
+
encoder_parts.append((f"x == {repr(const)}", repr(const)))
|
|
436
|
+
case _:
|
|
437
|
+
encoder_parts.append(("isinstance(x, (int, float))", "x"))
|
|
438
|
+
elif t.type == "boolean":
|
|
439
|
+
encoder_parts.append(("isinstance(x, bool)", "x"))
|
|
440
|
+
elif t.type == "null" or t.type == "undefined":
|
|
441
|
+
encoder_parts.append(("x is None", "None"))
|
|
442
|
+
else:
|
|
443
|
+
# Fallback for other types
|
|
444
|
+
match type_name:
|
|
418
445
|
case TypeName(value):
|
|
419
|
-
|
|
446
|
+
encoder_parts.append((None, f"encode_{value}(x)"))
|
|
447
|
+
case LiteralTypeExpr(const):
|
|
448
|
+
encoder_parts.append((None, repr(const)))
|
|
420
449
|
case NoneTypeExpr():
|
|
421
|
-
|
|
422
|
-
case
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
450
|
+
encoder_parts.append((None, "None"))
|
|
451
|
+
case _:
|
|
452
|
+
encoder_parts.append((None, "x"))
|
|
453
|
+
|
|
454
|
+
# Build the ternary chain from encoder_parts
|
|
455
|
+
typeddict_encoder = list[str]()
|
|
456
|
+
for i, (type_check, encoder_expr) in enumerate(encoder_parts):
|
|
457
|
+
is_last = i == len(encoder_parts) - 1
|
|
458
|
+
if is_last or type_check is None:
|
|
459
|
+
# Last item or no type check - just the expression
|
|
460
|
+
typeddict_encoder.append(encoder_expr)
|
|
461
|
+
else:
|
|
462
|
+
# Add expression with type check
|
|
463
|
+
typeddict_encoder.append(f"{encoder_expr} if {type_check} else")
|
|
434
464
|
if permit_unknown_members:
|
|
435
465
|
union = _make_open_union_type_expr(any_of)
|
|
436
466
|
else:
|
|
@@ -19,7 +19,7 @@ replit_river/transport_options.py,sha256=Kx3n6_x6sA69WV52EUvm-GzJhDaaewUQzbtcdPl
|
|
|
19
19
|
replit_river/websocket_wrapper.py,sha256=xrk421A5eXTH2bjAcNeBZN96zTO6xQsl0VS9qcwus6M,814
|
|
20
20
|
replit_river/codegen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
21
|
replit_river/codegen/__main__.py,sha256=LyKe1OXIyev0BuUcu43iu6zBLJzeogQ8DocxDkALD-Q,153
|
|
22
|
-
replit_river/codegen/client.py,sha256=
|
|
22
|
+
replit_river/codegen/client.py,sha256=w8CrFss2-0k0ukCtP6LlPftzSrm7wNgDmuCXTzsr9EQ,62870
|
|
23
23
|
replit_river/codegen/format.py,sha256=pLa9nWlw8hTOnjzZjMsMpgcmNYiLaF5VAHNQTwwJ7Zw,285
|
|
24
24
|
replit_river/codegen/run.py,sha256=InJaUDJft80pY7v2l-LoXHr8HYg3Bmb_6XQvlqgvxv4,3170
|
|
25
25
|
replit_river/codegen/schema.py,sha256=y3kzrEPgzW9gKMjqiF2souZk47mE_kuFkHlsxRdD560,5344
|
|
@@ -29,7 +29,7 @@ replit_river/v2/__init__.py,sha256=Fi4wP87qHOQwaWQmVbPJOOiGfkiZ6gTWg5bF5J8je5s,1
|
|
|
29
29
|
replit_river/v2/client.py,sha256=PQ1qz15lFTdMOs0kktBdzMUEYD66OnJJN0loYFVjdn4,7241
|
|
30
30
|
replit_river/v2/client_transport.py,sha256=swtsFoWIX8nnG5cBeHMkZSZsJ5SW-VbdNHBdLtldMgU,3445
|
|
31
31
|
replit_river/v2/session.py,sha256=8EMKw8bevoIrMfQBKMl3oXFlOJ91lzjmuqsm3qZN8Ts,54147
|
|
32
|
-
replit_river-0.17.
|
|
33
|
-
replit_river-0.17.
|
|
34
|
-
replit_river-0.17.
|
|
35
|
-
replit_river-0.17.
|
|
32
|
+
replit_river-0.17.14.dist-info/METADATA,sha256=YWXZDV75qxfsJOebUMG6j4gOwrhFUjYzO_ADA2JMIV8,4794
|
|
33
|
+
replit_river-0.17.14.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
34
|
+
replit_river-0.17.14.dist-info/licenses/LICENSE,sha256=kyZ5E3kOH4dzPet_xD0w6xi04e-0fGT0HRMhKyLyLC0,1063
|
|
35
|
+
replit_river-0.17.14.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|