Skip to content

Commit 390ade8

Browse files
committed
Ensure that <Never>.x is Never
1 parent f846af7 commit 390ade8

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

mypy/checkmember.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
TypeVarLikeType,
7171
TypeVarTupleType,
7272
TypeVarType,
73+
UninhabitedType,
7374
UnionType,
7475
get_proper_type,
7576
)
@@ -253,6 +254,8 @@ def _analyze_member_access(
253254
elif isinstance(typ, DeletedType):
254255
mx.msg.deleted_as_rvalue(typ, mx.context)
255256
return AnyType(TypeOfAny.from_error)
257+
elif isinstance(typ, UninhabitedType):
258+
return UninhabitedType()
256259
return report_missing_attribute(mx.original_type, typ, name, mx)
257260

258261

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: Unsupported left operand type for + ("Never")
1509+
return x + 1 if isinstance(x, int) else x + "a" # E: "Never" not callable
15101510
[builtins fixtures/isinstancelist.pyi]
15111511

15121512
-- Special cases

test-data/unit/check-isinstance.test

Lines changed: 3 additions & 3 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: Unsupported left operand type for + ("Never")
739+
x + 'a' # E: "Never" not callable
740740
break
741741
_ = "unreachable" # E: Statement is unreachable
742742
x + [1] # E: Unsupported operand types for + ("int" and "List[int]") \
@@ -1274,7 +1274,7 @@ if isinstance(y, int) and isinstance(x, B): # E: Subclass of "A" and "int" cann
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 \
12761276
# E: Right operand of "and" is never evaluated \
1277-
# E: Unsupported left operand type for > ("Never")
1277+
# E: "Never" not callable
12781278
_ = "unreachable" # E: Statement is unreachable
12791279
[builtins fixtures/isinstancelist.pyi]
12801280

@@ -2428,7 +2428,7 @@ class B:
24282428
def t0(self) -> None:
24292429
if isinstance(self, A0): # E: Subclass of "B" and "A0" cannot exist: would have incompatible method signatures
24302430
x0: Literal[0] = self.f() # E: Statement is unreachable \
2431-
# E: "Never" has no attribute "f"
2431+
# E: "Never" not callable
24322432

24332433
def t1(self) -> None:
24342434
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: Unsupported left operand type for + ("Never")
588+
x is not None and x + 42 # E: "Never" not callable
589589
[builtins fixtures/isinstance.pyi]
590590

591591
[case testOptionalLambdaInference]

0 commit comments

Comments
 (0)