@@ -8015,24 +8015,20 @@ def conditional_types(
8015
8015
# attempt to narrow anything. Instead, we broaden the expr to Any to
8016
8016
# avoid false positives
8017
8017
return proposed_type , default
8018
- elif not any ( # handle concrete subtypes
8018
+ elif not any (
8019
8019
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 )
8033
8027
)
8034
8028
)
8035
- return yes_type , no_type
8029
+ ):
8030
+ # Expression is always of one of the types in proposed_type_ranges
8031
+ return default , UninhabitedType ()
8036
8032
elif not is_overlapping_types (current_type , proposed_type , ignore_promotions = True ):
8037
8033
# Expression is never of any type in proposed_type_ranges
8038
8034
return UninhabitedType (), default
0 commit comments