diff --git a/mypy/semanal.py b/mypy/semanal.py index 025bbce85d67..a948b5c8834d 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -2245,6 +2245,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) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index a697c32d7c49..cda3711b06a3 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -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