Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions replit_river/codegen/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from textwrap import dedent, indent
from typing import (
Any,
Dict,
List,
Literal,
Expand Down Expand Up @@ -179,7 +180,15 @@ class RiverIntersectionType(BaseModel):
allOf: List["RiverType"]


RiverType = Union[RiverConcreteType, RiverUnionType, RiverIntersectionType]
class RiverNotType(BaseModel):
"""This is used to represent void / never."""

not_: Any = Field(..., alias="not")


RiverType = Union[
RiverConcreteType, RiverUnionType, RiverNotType, RiverIntersectionType
]


class RiverProcedure(BaseModel):
Expand Down Expand Up @@ -230,7 +239,9 @@ def encode_type(
) -> Tuple[TypeExpression, list[ModuleName], list[FileContents], set[TypeName]]:
encoder_name: Optional[str] = None # defining this up here to placate mypy
chunks: List[FileContents] = []
if isinstance(type, RiverUnionType):
if isinstance(type, RiverNotType):
return (TypeName("None"), [], [], set())
elif isinstance(type, RiverUnionType):
typeddict_encoder = list[str]()
encoder_names: set[TypeName] = set()

Expand Down Expand Up @@ -476,8 +487,6 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
# Handle the case where type is not specified
typeddict_encoder.append("x")
return (TypeName("Any"), [], [], set())
elif type.type == "not":
return (TypeName("None"), [], [], set())
elif type.type == "string":
if type.const:
typeddict_encoder.append(repr(type.const))
Expand Down Expand Up @@ -566,7 +575,9 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
encoder_name = None
chunks.extend(contents)
if base_model == "TypedDict":
if isinstance(prop, RiverUnionType):
if isinstance(prop, RiverNotType):
typeddict_encoder.append("'not implemented'")
elif isinstance(prop, RiverUnionType):
encoder_name = TypeName(
f"encode_{ensure_literal_type(type_name)}"
)
Expand All @@ -585,9 +596,7 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
safe_name = "kind"
else:
safe_name = name
if prop.type == "not":
typeddict_encoder.append("'not implemented'")
elif prop.type == "object" and not prop.patternProperties:
if prop.type == "object" and not prop.patternProperties:
encoder_name = TypeName(
f"encode_{ensure_literal_type(type_name)}"
)
Expand Down
Loading