77 Any ,
88 Callable ,
99 Literal ,
10- Optional ,
1110 OrderedDict ,
1211 Sequence ,
1312 Set ,
7675from typing import (
7776 Any,
7877 Literal,
79- Optional,
8078 Mapping,
8179 NotRequired,
8280 Union,
9694
9795
9896class RiverConcreteType (BaseModel ):
99- type : Optional [ str ] = Field (default = None )
97+ type : str | None = Field (default = None )
10098 properties : dict [str , "RiverType" ] = Field (default_factory = lambda : dict ())
10199 required : Set [str ] = Field (default = set ())
102- items : Optional [ "RiverType" ] = Field (default = None )
103- const : Optional [ Union [str , int ]] = Field (default = None )
100+ items : "RiverType | None" = Field (default = None )
101+ const : Union [str , int ] | None = Field (default = None )
104102 patternProperties : dict [str , "RiverType" ] = Field (default_factory = lambda : dict ())
105103
106104
@@ -124,14 +122,14 @@ class RiverNotType(BaseModel):
124122
125123
126124class RiverProcedure (BaseModel ):
127- init : Optional [ RiverType ] = Field (default = None )
125+ init : RiverType | None = Field (default = None )
128126 input : RiverType
129127 output : RiverType
130- errors : Optional [ RiverType ] = Field (default = None )
128+ errors : RiverType | None = Field (default = None )
131129 type : (
132130 Literal ["rpc" ] | Literal ["stream" ] | Literal ["subscription" ] | Literal ["upload" ]
133131 )
134- description : Optional [ str ] = Field (default = None )
132+ description : str | None = Field (default = None )
135133
136134
137135class RiverService (BaseModel ):
@@ -140,7 +138,7 @@ class RiverService(BaseModel):
140138
141139class RiverSchema (BaseModel ):
142140 services : dict [str , RiverService ]
143- handshakeSchema : Optional [ RiverConcreteType ] = Field (default = None )
141+ handshakeSchema : RiverConcreteType | None = Field (default = None )
144142
145143
146144RiverSchemaFile = RootModel [RiverSchema ]
@@ -640,7 +638,7 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
640638 """
641639 )
642640 current_chunks .append (
643- f" kind: Optional[ { render_type_expr (type_name )} ] { value } "
641+ f" kind: { render_type_expr (type_name )} | None { value } "
644642 )
645643 else :
646644 value = ""
@@ -663,7 +661,7 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
663661 reindent (
664662 " " ,
665663 f"""\
666- { name } : NotRequired[Optional[ { render_type_expr (type_name )} ]]
664+ { name } : NotRequired[{ render_type_expr (type_name )} ] | None
667665 """ ,
668666 )
669667 )
@@ -672,7 +670,7 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
672670 reindent (
673671 " " ,
674672 f"""\
675- { name } : Optional[ { render_type_expr (type_name )} ] = None
673+ { name } : { render_type_expr (type_name )} | None = None
676674 """ ,
677675 )
678676 )
@@ -772,7 +770,7 @@ def __init__(self, client: river.Client[Any]):
772770 ]
773771 for name , procedure in schema .procedures .items ():
774772 module_names = [ModuleName (name )]
775- init_type : Optional [ TypeExpression ] = None
773+ init_type : TypeExpression | None = None
776774 if procedure .init :
777775 init_type , module_info , init_chunks , encoder_names = encode_type (
778776 procedure .init ,
@@ -852,7 +850,7 @@ def __init__(self, client: river.Client[Any]):
852850 """
853851
854852 # Init renderer
855- render_init_method : Optional [ str ] = None
853+ render_init_method : str | None = None
856854 if init_type and procedure .init is not None :
857855 if input_base_class == "TypedDict" :
858856 if is_literal (procedure .init ):
@@ -878,7 +876,7 @@ def __init__(self, client: river.Client[Any]):
878876 )
879877
880878 # Input renderer
881- render_input_method : Optional [ str ] = None
879+ render_input_method : str | None = None
882880 if input_base_class == "TypedDict" :
883881 if is_literal (procedure .input ):
884882 render_input_method = "lambda x: x"
0 commit comments