@@ -388,35 +388,35 @@ def _infer_constraints(
388388 if isinstance (template_proper , UnionType ) and len (template_proper .items ) == 2 :
389389 type_var_items = []
390390 non_type_var_items = []
391-
391+
392392 for t_item in template_proper .items :
393393 t_item_proper = get_proper_type (t_item )
394394 if isinstance (t_item_proper , TypeVarType ):
395395 type_var_items .append (t_item_proper )
396396 else :
397397 non_type_var_items .append (t_item_proper )
398-
398+
399399 if len (type_var_items ) == 1 and len (non_type_var_items ) == 1 :
400400 # This is Union[T, X] vs Union[Y, Z] case
401401 type_var = type_var_items [0 ]
402402 non_type_var = non_type_var_items [0 ]
403-
403+
404404 # Check if any actual items are NOT subtypes of the non-type-var part
405405 compatible_items = []
406406 actual_proper = get_proper_type (actual )
407407 if isinstance (actual_proper , UnionType ):
408408 for actual_item in actual_proper .items :
409409 if not mypy .subtypes .is_subtype (actual_item , non_type_var ):
410410 compatible_items .append (actual_item )
411-
411+
412412 # If we have compatible items, create constraint for the type variable
413413 if compatible_items :
414414 if len (compatible_items ) == 1 :
415415 return [Constraint (type_var , SUBTYPE_OF , compatible_items [0 ])]
416416 else :
417417 union_type = UnionType .make_union (compatible_items )
418418 return [Constraint (type_var , SUBTYPE_OF , union_type )]
419-
419+
420420 res = []
421421 for a_item in actual .items :
422422 # `orig_template` has to be preserved intact in case it's recursive.
0 commit comments