Skip to content

Commit 9a3e374

Browse files
Fix narrowing when current_type is Any.
1 parent c4471a1 commit 9a3e374

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

mypy/checker.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8024,7 +8024,15 @@ def conditional_types(
80248024
isinstance(proposed_type, CallableType)
80258025
or (isinstance(proposed_type, Instance) and proposed_type.type.is_protocol)
80268026
) and is_subtype(current_type, proposed_type, ignore_promotions=True):
8027-
return default, UninhabitedType()
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
8033+
)
8034+
)
8035+
return yes_type, no_type
80288036
elif not is_overlapping_types(current_type, proposed_type, ignore_promotions=True):
80298037
# Expression is never of any type in proposed_type_ranges
80308038
return UninhabitedType(), default

0 commit comments

Comments
 (0)