@@ -8015,24 +8015,20 @@ def conditional_types(
80158015 # attempt to narrow anything. Instead, we broaden the expr to Any to
80168016 # avoid false positives
80178017 return proposed_type , default
8018- elif not any ( # handle concrete subtypes
8018+ elif not any (
80198019 type_range .is_upper_bound for type_range in proposed_type_ranges
8020- ) and is_proper_subtype (current_type , proposed_type , ignore_promotions = True ):
8021- # Expression is always of one of the types in proposed_type_ranges
8022- return default , UninhabitedType ()
8023- elif ( # handle structural subtypes
8024- isinstance (proposed_type , CallableType )
8025- or (isinstance (proposed_type , Instance ) and proposed_type .type .is_protocol )
8026- ) and is_subtype (current_type , proposed_type , ignore_promotions = True ):
8027- yes_type = default
8028- no_type = (
8029- None
8030- if yes_type is None
8031- else restrict_subtype_away (
8032- current_type , yes_type , consider_runtime_isinstance = consider_runtime_isinstance
8020+ ) and ( # concrete subtypes
8021+ is_proper_subtype (current_type , proposed_type , ignore_promotions = True )
8022+ or ( # structural subtypes
8023+ is_subtype (current_type , proposed_type , ignore_promotions = True )
8024+ and (
8025+ isinstance (proposed_type , CallableType )
8026+ or (isinstance (proposed_type , Instance ) and proposed_type .type .is_protocol )
80338027 )
80348028 )
8035- return yes_type , no_type
8029+ ):
8030+ # Expression is always of one of the types in proposed_type_ranges
8031+ return default , UninhabitedType ()
80368032 elif not is_overlapping_types (current_type , proposed_type , ignore_promotions = True ):
80378033 # Expression is never of any type in proposed_type_ranges
80388034 return UninhabitedType (), default
0 commit comments