66from typing import (
77 Any ,
88 Callable ,
9- Dict ,
10- List ,
119 Literal ,
1210 Optional ,
1311 OrderedDict ,
1412 Sequence ,
1513 Set ,
1614 TextIO ,
17- Tuple ,
1815 Union ,
1916 cast ,
2017)
7875import datetime
7976from typing import (
8077 Any,
81- Dict,
82- List,
8378 Literal,
8479 Optional,
8580 Mapping,
10297
10398class RiverConcreteType (BaseModel ):
10499 type : Optional [str ] = Field (default = None )
105- properties : Dict [str , "RiverType" ] = Field (default_factory = lambda : dict ())
100+ properties : dict [str , "RiverType" ] = Field (default_factory = lambda : dict ())
106101 required : Set [str ] = Field (default = set ())
107102 items : Optional ["RiverType" ] = Field (default = None )
108103 const : Optional [Union [str , int ]] = Field (default = None )
109- patternProperties : Dict [str , "RiverType" ] = Field (default_factory = lambda : dict ())
104+ patternProperties : dict [str , "RiverType" ] = Field (default_factory = lambda : dict ())
110105
111106
112107class RiverUnionType (BaseModel ):
113- anyOf : List ["RiverType" ]
108+ anyOf : list ["RiverType" ]
114109
115110
116111class RiverIntersectionType (BaseModel ):
117- allOf : List ["RiverType" ]
112+ allOf : list ["RiverType" ]
118113
119114
120115class RiverNotType (BaseModel ):
@@ -140,11 +135,11 @@ class RiverProcedure(BaseModel):
140135
141136
142137class RiverService (BaseModel ):
143- procedures : Dict [str , RiverProcedure ]
138+ procedures : dict [str , RiverProcedure ]
144139
145140
146141class RiverSchema (BaseModel ):
147- services : Dict [str , RiverService ]
142+ services : dict [str , RiverService ]
148143 handshakeSchema : Optional [RiverConcreteType ] = Field (default = None )
149144
150145
@@ -166,9 +161,9 @@ def encode_type(
166161 base_model : str ,
167162 in_module : list [ModuleName ],
168163 permit_unknown_members : bool ,
169- ) -> Tuple [TypeExpression , list [ModuleName ], list [FileContents ], set [TypeName ]]:
164+ ) -> tuple [TypeExpression , list [ModuleName ], list [FileContents ], set [TypeName ]]:
170165 encoder_name : TypeName | None = None # defining this up here to placate mypy
171- chunks : List [FileContents ] = []
166+ chunks : list [FileContents ] = []
172167 if isinstance (type , RiverNotType ):
173168 return (NoneTypeExpr (), [], [], set ())
174169 elif isinstance (type , RiverUnionType ):
@@ -190,7 +185,7 @@ def flatten_union(tpe: RiverType) -> list[RiverType]:
190185
191186 type = RiverUnionType (anyOf = flatten_union (type ))
192187
193- one_of_candidate_types : List [RiverConcreteType ] = [
188+ one_of_candidate_types : list [RiverConcreteType ] = [
194189 t
195190 for _t in type .anyOf
196191 for t in (_t .anyOf if isinstance (_t , RiverUnionType ) else [_t ])
@@ -238,7 +233,7 @@ def flatten_union(tpe: RiverType) -> list[RiverType]:
238233 (discriminator_value , []),
239234 )[1 ].append (oneof_t )
240235
241- one_of : List [TypeExpression ] = []
236+ one_of : list [TypeExpression ] = []
242237 if discriminator_name == "$kind" :
243238 discriminator_name = "kind"
244239 for pfx , (discriminator_value , oneof_ts ) in one_of_pending .items ():
@@ -354,7 +349,7 @@ def {_field_name}(
354349 # End of stable union detection
355350 # Restore the non-flattened union type
356351 type = original_type
357- any_of : List [TypeExpression ] = []
352+ any_of : list [TypeExpression ] = []
358353
359354 typeddict_encoder = []
360355 for i , t in enumerate (type .anyOf ):
@@ -521,7 +516,7 @@ def extract_props(tpe: RiverType) -> list[dict[str, RiverType]]:
521516 return (DictTypeExpr (type_name ), module_info , type_chunks , encoder_names )
522517 assert type .type == "object" , type .type
523518
524- current_chunks : List [str ] = [
519+ current_chunks : list [str ] = [
525520 f"class { render_literal_type (prefix )} ({ base_model } ):"
526521 ]
527522 # For the encoder path, do we need "x" to be bound?
@@ -731,7 +726,7 @@ def generate_common_client(
731726 client_name : str ,
732727 handshake_type : HandshakeType ,
733728 handshake_chunks : Sequence [str ],
734- modules : list [Tuple [ModuleName , ClassName ]],
729+ modules : list [tuple [ModuleName , ClassName ]],
735730) -> FileContents :
736731 chunks : list [str ] = [ROOT_FILE_HEADER ]
737732 chunks .extend (
@@ -763,10 +758,10 @@ def generate_individual_service(
763758 schema_name : str ,
764759 schema : RiverService ,
765760 input_base_class : Literal ["TypedDict" ] | Literal ["BaseModel" ],
766- ) -> Tuple [ModuleName , ClassName , dict [RenderedPath , FileContents ]]:
767- serdes : list [Tuple [list [TypeName ], list [ModuleName ], list [FileContents ]]] = []
761+ ) -> tuple [ModuleName , ClassName , dict [RenderedPath , FileContents ]]:
762+ serdes : list [tuple [list [TypeName ], list [ModuleName ], list [FileContents ]]] = []
768763 class_name = ClassName (f"{ schema_name .title ()} Service" )
769- current_chunks : List [str ] = [
764+ current_chunks : list [str ] = [
770765 dedent (
771766 f"""\
772767 class { class_name } :
@@ -1124,7 +1119,7 @@ def generate_river_client_module(
11241119 else :
11251120 handshake_type = HandshakeType ("Literal[None]" )
11261121
1127- modules : list [Tuple [ModuleName , ClassName ]] = []
1122+ modules : list [tuple [ModuleName , ClassName ]] = []
11281123 input_base_class : Literal ["TypedDict" ] | Literal ["BaseModel" ] = (
11291124 "TypedDict" if typed_dict_inputs else "BaseModel"
11301125 )
0 commit comments