@@ -347,29 +347,33 @@ def visit_instance(self, template: Instance) -> List[Constraint]:
347
347
template .type .has_base (instance .type .fullname )):
348
348
mapped = map_instance_to_supertype (template , instance .type )
349
349
tvars = mapped .type .defn .type_vars
350
- for i in range (len (instance .args )):
350
+ # N.B: We use zip instead of indexing because the lengths might have
351
+ # mismatches during daemon reprocessing.
352
+ for tvar , mapped_arg , instance_arg in zip (tvars , mapped .args , instance .args ):
351
353
# The constraints for generic type parameters depend on variance.
352
354
# Include constraints from both directions if invariant.
353
- if tvars [ i ] .variance != CONTRAVARIANT :
355
+ if tvar .variance != CONTRAVARIANT :
354
356
res .extend (infer_constraints (
355
- mapped . args [ i ], instance . args [ i ] , self .direction ))
356
- if tvars [ i ] .variance != COVARIANT :
357
+ mapped_arg , instance_arg , self .direction ))
358
+ if tvar .variance != COVARIANT :
357
359
res .extend (infer_constraints (
358
- mapped . args [ i ], instance . args [ i ] , neg_op (self .direction )))
360
+ mapped_arg , instance_arg , neg_op (self .direction )))
359
361
return res
360
362
elif (self .direction == SUPERTYPE_OF and
361
363
instance .type .has_base (template .type .fullname )):
362
364
mapped = map_instance_to_supertype (instance , template .type )
363
365
tvars = template .type .defn .type_vars
364
- for j in range (len (template .args )):
366
+ # N.B: We use zip instead of indexing because the lengths might have
367
+ # mismatches during daemon reprocessing.
368
+ for tvar , mapped_arg , template_arg in zip (tvars , mapped .args , template .args ):
365
369
# The constraints for generic type parameters depend on variance.
366
370
# Include constraints from both directions if invariant.
367
- if tvars [ j ] .variance != CONTRAVARIANT :
371
+ if tvar .variance != CONTRAVARIANT :
368
372
res .extend (infer_constraints (
369
- template . args [ j ], mapped . args [ j ] , self .direction ))
370
- if tvars [ j ] .variance != COVARIANT :
373
+ template_arg , mapped_arg , self .direction ))
374
+ if tvar .variance != COVARIANT :
371
375
res .extend (infer_constraints (
372
- template . args [ j ], mapped . args [ j ] , neg_op (self .direction )))
376
+ template_arg , mapped_arg , neg_op (self .direction )))
373
377
return res
374
378
if (template .type .is_protocol and self .direction == SUPERTYPE_OF and
375
379
# We avoid infinite recursion for structural subtypes by checking
0 commit comments