Skip to content

Commit b40c3d0

Browse files
sobolevnJukkaL
authored andcommitted
Handle NoReturn type aliases (#11912)
1 parent 3f2143d commit b40c3d0

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

mypy/semanal.py

+6
Original file line numberDiff line numberDiff line change
@@ -2245,6 +2245,12 @@ def is_type_ref(self, rv: Expression, bare: bool = False) -> bool:
22452245
return True
22462246
# Assignment color = Color['RED'] defines a variable, not an alias.
22472247
return not rv.node.is_enum
2248+
if isinstance(rv.node, Var):
2249+
return rv.node.fullname in (
2250+
'typing.NoReturn',
2251+
'typing_extensions.NoReturn',
2252+
'mypy_extensions.NoReturn',
2253+
)
22482254

22492255
if isinstance(rv, NameExpr):
22502256
n = self.lookup(rv.name, rv)

test-data/unit/check-type-aliases.test

+8
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ def f(x: A) -> None:
5050
f(1)
5151
f('x')
5252

53+
[case testNoReturnTypeAlias]
54+
# https://github.com/python/mypy/issues/11903
55+
from typing import NoReturn
56+
Never = NoReturn
57+
a: Never # Used to be an error here
58+
59+
def f(a: Never): ...
60+
f(5) # E: Argument 1 to "f" has incompatible type "int"; expected "NoReturn"
5361
[case testImportUnionAlias]
5462
import typing
5563
from _m import U

0 commit comments

Comments
 (0)