@@ -152,7 +152,7 @@ def visit_decorator(self, dec: Decorator) -> None:
152
152
for expr in dec .decorators :
153
153
preserve_type = False
154
154
if isinstance (expr , RefExpr ) and isinstance (expr .node , FuncDef ):
155
- if is_identity_signature (expr .node .type ):
155
+ if expr . node . type and is_identity_signature (expr .node .type ):
156
156
preserve_type = True
157
157
if not preserve_type :
158
158
decorator_preserves_type = False
@@ -246,31 +246,38 @@ def perform_transform(self, node: Union[Node, SymbolTableNode],
246
246
transform : Callable [[Type ], Type ]) -> None :
247
247
"""Apply transform to all types associated with node."""
248
248
if isinstance (node , ForStmt ):
249
- node .index_type = transform (node .index_type )
249
+ if node .index_type :
250
+ node .index_type = transform (node .index_type )
250
251
self .transform_types_in_lvalue (node .index , transform )
251
252
if isinstance (node , WithStmt ):
252
- node .target_type = transform (node .target_type )
253
+ if node .target_type :
254
+ node .target_type = transform (node .target_type )
253
255
for n in node .target :
254
256
if isinstance (n , NameExpr ) and isinstance (n .node , Var ) and n .node .type :
255
257
n .node .type = transform (n .node .type )
256
258
if isinstance (node , (FuncDef , CastExpr , AssignmentStmt , TypeAliasExpr , Var )):
259
+ assert node .type , "Scheduled patch for non-existent type"
257
260
node .type = transform (node .type )
258
261
if isinstance (node , NewTypeExpr ):
262
+ assert node .old_type , "Scheduled patch for non-existent type"
259
263
node .old_type = transform (node .old_type )
260
264
if isinstance (node , TypeVarExpr ):
261
265
if node .upper_bound :
262
266
node .upper_bound = transform (node .upper_bound )
263
267
if node .values :
264
268
node .values = [transform (v ) for v in node .values ]
265
269
if isinstance (node , TypedDictExpr ):
270
+ assert node .info .typeddict_type , "Scheduled patch for non-existent type"
266
271
node .info .typeddict_type = cast (TypedDictType ,
267
272
transform (node .info .typeddict_type ))
268
273
if isinstance (node , NamedTupleExpr ):
274
+ assert node .info .tuple_type , "Scheduled patch for non-existent type"
269
275
node .info .tuple_type = cast (TupleType ,
270
276
transform (node .info .tuple_type ))
271
277
if isinstance (node , TypeApplication ):
272
278
node .types = [transform (t ) for t in node .types ]
273
279
if isinstance (node , SymbolTableNode ):
280
+ assert node .type_override , "Scheduled patch for non-existent type"
274
281
node .type_override = transform (node .type_override )
275
282
if isinstance (node , TypeInfo ):
276
283
for tvar in node .defn .type_vars :
@@ -296,7 +303,8 @@ def transform_types_in_lvalue(self, lvalue: Lvalue,
296
303
if isinstance (lvalue , RefExpr ):
297
304
if isinstance (lvalue .node , Var ):
298
305
var = lvalue .node
299
- var .type = transform (var .type )
306
+ if var .type :
307
+ var .type = transform (var .type )
300
308
elif isinstance (lvalue , TupleExpr ):
301
309
for item in lvalue .items :
302
310
self .transform_types_in_lvalue (item , transform )
@@ -355,7 +363,7 @@ def fail(self, msg: str, ctx: Context, *, blocker: bool = False) -> None:
355
363
def fail_blocker (self , msg : str , ctx : Context ) -> None :
356
364
self .fail (msg , ctx , blocker = True )
357
365
358
- def builtin_type (self , name : str , args : List [Type ] = None ) -> Instance :
366
+ def builtin_type (self , name : str , args : Optional [ List [Type ] ] = None ) -> Instance :
359
367
names = self .modules ['builtins' ]
360
368
sym = names .names [name ]
361
369
node = sym .node
0 commit comments