Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2247,6 +2247,12 @@ def is_type_ref(self, rv: Expression, bare: bool = False) -> bool:
return True
# Assignment color = Color['RED'] defines a variable, not an alias.
return not rv.node.is_enum
if isinstance(rv.node, Var):
return rv.node.fullname in (
'typing.NoReturn',
'typing_extensions.NoReturn',
'mypy_extensions.NoReturn',
)

if isinstance(rv, NameExpr):
n = self.lookup(rv.name, rv)
Expand Down
8 changes: 8 additions & 0 deletions test-data/unit/check-type-aliases.test
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def f(x: A) -> None:
f(1)
f('x')

[case testNoReturnTypeAlias]
# https://github.com/python/mypy/issues/11903
from typing import NoReturn
Never = NoReturn
a: Never # Used to be an error here

def f(a: Never): ...
f(5) # E: Argument 1 to "f" has incompatible type "int"; expected "NoReturn"
[case testImportUnionAlias]
import typing
from _m import U
Expand Down