Skip to content

Commit f3ba149

Browse files
committed
Ensure that <Never>() is Never
1 parent 390ade8 commit f3ba149

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

mypy/checkexpr.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,9 @@ def check_call(
16381638
object_type,
16391639
original_type=callee,
16401640
)
1641+
elif isinstance(callee, UninhabitedType):
1642+
self.infer_arg_types_in_empty_context(args)
1643+
return (UninhabitedType(), UninhabitedType())
16411644
else:
16421645
return self.msg.not_callable(callee, context), AnyType(TypeOfAny.from_error)
16431646

test-data/unit/check-expressions.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,7 @@ z = x.append(y) if bool() else x.append(y) # E: "append" of "list" does not retu
15061506
from typing import TypeVar
15071507
T = TypeVar("T", int, str)
15081508
def foo(x: T) -> T:
1509-
return x + 1 if isinstance(x, int) else x + "a" # E: "Never" not callable
1509+
return x + 1 if isinstance(x, int) else x + "a"
15101510
[builtins fixtures/isinstancelist.pyi]
15111511

15121512
-- Special cases

test-data/unit/check-isinstance.test

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ while bool():
736736
# TODO: only report unreachability once
737737
elif isinstance(x, str): # E: Statement is unreachable
738738
_ = "unreachable" # E: Statement is unreachable
739-
x + 'a' # E: "Never" not callable
739+
x + 'a'
740740
break
741741
_ = "unreachable" # E: Statement is unreachable
742742
x + [1] # E: Unsupported operand types for + ("int" and "List[int]") \
@@ -1273,8 +1273,7 @@ if isinstance(y, int) and isinstance(x, B): # E: Subclass of "A" and "int" cann
12731273
# E: Right operand of "and" is never evaluated
12741274
_ = "unreachable" # E: Statement is unreachable
12751275
if isinstance(y, int) and y > 42: # E: Subclass of "A" and "int" cannot exist: would have incompatible method signatures \
1276-
# E: Right operand of "and" is never evaluated \
1277-
# E: "Never" not callable
1276+
# E: Right operand of "and" is never evaluated
12781277
_ = "unreachable" # E: Statement is unreachable
12791278
[builtins fixtures/isinstancelist.pyi]
12801279

@@ -2427,8 +2426,7 @@ class B:
24272426

24282427
def t0(self) -> None:
24292428
if isinstance(self, A0): # E: Subclass of "B" and "A0" cannot exist: would have incompatible method signatures
2430-
x0: Literal[0] = self.f() # E: Statement is unreachable \
2431-
# E: "Never" not callable
2429+
x0: Literal[0] = self.f() # E: Statement is unreachable
24322430

24332431
def t1(self) -> None:
24342432
if isinstance(self, A1):

test-data/unit/check-optional.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ x is not None and x + '42' # E: Unsupported operand types for + ("int" and "str
585585
from typing import Optional
586586

587587
x: None = None
588-
x is not None and x + 42 # E: "Never" not callable
588+
x is not None and x + 42
589589
[builtins fixtures/isinstance.pyi]
590590

591591
[case testOptionalLambdaInference]

0 commit comments

Comments
 (0)