Skip to content

Commit f3bbfb9

Browse files
Turns out pydantic has never been able to correctly discern a RiverNotType
1 parent 3442e7f commit f3bbfb9

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

replit_river/codegen/client.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from pathlib import Path
55
from textwrap import dedent, indent
66
from typing import (
7-
Any,
87
Dict,
98
List,
109
Literal,
@@ -180,15 +179,7 @@ class RiverIntersectionType(BaseModel):
180179
allOf: List["RiverType"]
181180

182181

183-
class RiverNotType(BaseModel):
184-
"""This is used to represent void / never."""
185-
186-
not_: Any = Field(..., alias="not")
187-
188-
189-
RiverType = Union[
190-
RiverConcreteType, RiverUnionType, RiverNotType, RiverIntersectionType
191-
]
182+
RiverType = Union[RiverConcreteType, RiverUnionType, RiverIntersectionType]
192183

193184

194185
class RiverProcedure(BaseModel):
@@ -239,8 +230,6 @@ def encode_type(
239230
) -> Tuple[TypeExpression, list[ModuleName], list[FileContents], set[TypeName]]:
240231
encoder_name: Optional[str] = None # defining this up here to placate mypy
241232
chunks: List[FileContents] = []
242-
if isinstance(type, RiverNotType):
243-
return (TypeName("None"), [], [], set())
244233
if isinstance(type, RiverUnionType):
245234
typeddict_encoder = list[str]()
246235
encoder_names: set[TypeName] = set()
@@ -460,7 +449,7 @@ def flatten_union(tpe: RiverType) -> list[RiverType]:
460449
)
461450
)
462451
return (prefix, in_module, chunks, encoder_names)
463-
if isinstance(type, RiverIntersectionType):
452+
elif isinstance(type, RiverIntersectionType):
464453

465454
def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
466455
if isinstance(tpe, RiverUnionType):
@@ -481,12 +470,14 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
481470
base_model,
482471
in_module,
483472
)
484-
if isinstance(type, RiverConcreteType):
473+
elif isinstance(type, RiverConcreteType):
485474
typeddict_encoder = list[str]()
486475
if type.type is None:
487476
# Handle the case where type is not specified
488477
typeddict_encoder.append("x")
489478
return (TypeName("Any"), [], [], set())
479+
elif type.type == "not":
480+
return (TypeName("None"), [], [], set())
490481
elif type.type == "string":
491482
if type.const:
492483
typeddict_encoder.append(repr(type.const))
@@ -575,9 +566,7 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
575566
encoder_name = None
576567
chunks.extend(contents)
577568
if base_model == "TypedDict":
578-
if isinstance(prop, RiverNotType):
579-
typeddict_encoder.append("'not implemented'")
580-
elif isinstance(prop, RiverUnionType):
569+
if isinstance(prop, RiverUnionType):
581570
encoder_name = TypeName(
582571
f"encode_{ensure_literal_type(type_name)}"
583572
)
@@ -596,7 +585,9 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
596585
safe_name = "kind"
597586
else:
598587
safe_name = name
599-
if prop.type == "object" and not prop.patternProperties:
588+
if prop.type == "not":
589+
typeddict_encoder.append("'not implemented'")
590+
elif prop.type == "object" and not prop.patternProperties:
600591
encoder_name = TypeName(
601592
f"encode_{ensure_literal_type(type_name)}"
602593
)

0 commit comments

Comments
 (0)