Skip to content

Commit 39eedb4

Browse files
fixed return type using mesonbuild mypy-prime failure
1 parent 07119e0 commit 39eedb4

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

mypy/checker.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

test-data/unit/check-isinstance.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,21 @@ while bool():
10861086
x + 'a'
10871087
[builtins fixtures/isinstance.pyi]
10881088

1089+
[case testUnreachableCode3]
1090+
# flags: --warn-unreachable --python-version 3.10
1091+
from collections.abc import Iterable
1092+
1093+
class A: ...
1094+
1095+
def test(dependencies: list[A] | None) -> None:
1096+
if dependencies is None:
1097+
dependencies = []
1098+
elif not isinstance(dependencies, Iterable):
1099+
dependencies = [dependencies] # E: Statement is unreachable
1100+
1101+
[builtins fixtures/isinstancelist.pyi]
1102+
[typing fixtures/typing-full.pyi]
1103+
10891104
[case testUnreachableWhileTrue]
10901105
def f(x: int) -> None:
10911106
while True:

0 commit comments

Comments
 (0)