@@ -397,13 +397,11 @@ def _infer_constraints(
397397 # be a supertype of the potential subtype, some item of the Union
398398 # must be a supertype of it.
399399 if direction == SUBTYPE_OF and isinstance (actual , UnionType ):
400- # If some of items is not a complete type, disregard that.
401- items = simplify_away_incomplete_types (actual .items )
402400 # We infer constraints eagerly -- try to find constraints for a type
403401 # variable if possible. This seems to help with some real-world
404402 # use cases.
405403 return any_constraints (
406- [infer_constraints_if_possible (template , a_item , direction ) for a_item in items ],
404+ [infer_constraints_if_possible (template , a_item , direction ) for a_item in actual . items ],
407405 eager = True ,
408406 )
409407 if direction == SUPERTYPE_OF and isinstance (template , UnionType ):
@@ -652,31 +650,6 @@ def _is_similar_constraints(x: list[Constraint], y: list[Constraint]) -> bool:
652650 return True
653651
654652
655- def simplify_away_incomplete_types (types : Iterable [Type ]) -> list [Type ]:
656- complete = [typ for typ in types if is_complete_type (typ )]
657- if complete :
658- return complete
659- else :
660- return list (types )
661-
662-
663- def is_complete_type (typ : Type ) -> bool :
664- """Is a type complete?
665-
666- A complete doesn't have uninhabited type components or (when not in strict
667- optional mode) None components.
668- """
669- return typ .accept (CompleteTypeVisitor ())
670-
671-
672- class CompleteTypeVisitor (BoolTypeQuery ):
673- def __init__ (self ) -> None :
674- super ().__init__ (ALL_STRATEGY )
675-
676- def visit_uninhabited_type (self , t : UninhabitedType ) -> bool :
677- return False
678-
679-
680653class ConstraintBuilderVisitor (TypeVisitor [list [Constraint ]]):
681654 """Visitor class for inferring type constraints."""
682655
0 commit comments