Skip to content

Commit ce42116

Browse files
authored
Handle NoReturn type aliases (#11912)
1 parent 37886c7 commit ce42116

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

mypy/semanal.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,6 +2247,12 @@ def is_type_ref(self, rv: Expression, bare: bool = False) -> bool:
22472247
return True
22482248
# Assignment color = Color['RED'] defines a variable, not an alias.
22492249
return not rv.node.is_enum
2250+
if isinstance(rv.node, Var):
2251+
return rv.node.fullname in (
2252+
'typing.NoReturn',
2253+
'typing_extensions.NoReturn',
2254+
'mypy_extensions.NoReturn',
2255+
)
22502256

22512257
if isinstance(rv, NameExpr):
22522258
n = self.lookup(rv.name, rv)

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

Lines changed: 8 additions & 0 deletions
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)