44from pathlib import Path
55from textwrap import dedent , indent
66from typing import (
7+ Any ,
78 Dict ,
89 List ,
910 Literal ,
@@ -179,7 +180,15 @@ class RiverIntersectionType(BaseModel):
179180 allOf : List ["RiverType" ]
180181
181182
182- RiverType = Union [RiverConcreteType , RiverUnionType , RiverIntersectionType ]
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+ ]
183192
184193
185194class RiverProcedure (BaseModel ):
@@ -230,7 +239,9 @@ def encode_type(
230239) -> Tuple [TypeExpression , list [ModuleName ], list [FileContents ], set [TypeName ]]:
231240 encoder_name : Optional [str ] = None # defining this up here to placate mypy
232241 chunks : List [FileContents ] = []
233- if isinstance (type , RiverUnionType ):
242+ if isinstance (type , RiverNotType ):
243+ return (TypeName ("None" ), [], [], set ())
244+ elif isinstance (type , RiverUnionType ):
234245 typeddict_encoder = list [str ]()
235246 encoder_names : set [TypeName ] = set ()
236247
@@ -476,8 +487,6 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
476487 # Handle the case where type is not specified
477488 typeddict_encoder .append ("x" )
478489 return (TypeName ("Any" ), [], [], set ())
479- elif type .type == "not" :
480- return (TypeName ("None" ), [], [], set ())
481490 elif type .type == "string" :
482491 if type .const :
483492 typeddict_encoder .append (repr (type .const ))
@@ -566,7 +575,9 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
566575 encoder_name = None
567576 chunks .extend (contents )
568577 if base_model == "TypedDict" :
569- if isinstance (prop , RiverUnionType ):
578+ if isinstance (prop , RiverNotType ):
579+ typeddict_encoder .append ("'not implemented'" )
580+ elif isinstance (prop , RiverUnionType ):
570581 encoder_name = TypeName (
571582 f"encode_{ ensure_literal_type (type_name )} "
572583 )
@@ -585,9 +596,7 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
585596 safe_name = "kind"
586597 else :
587598 safe_name = name
588- if prop .type == "not" :
589- typeddict_encoder .append ("'not implemented'" )
590- elif prop .type == "object" and not prop .patternProperties :
599+ if prop .type == "object" and not prop .patternProperties :
591600 encoder_name = TypeName (
592601 f"encode_{ ensure_literal_type (type_name )} "
593602 )
0 commit comments