Skip to content

Commit

Permalink
Handle NoReturn type aliases (#11912)
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn authored and JukkaL committed Jan 6, 2022
1 parent 3f2143d commit b40c3d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mypy/semanal.py
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions test-data/unit/check-type-aliases.test
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

0 comments on commit b40c3d0

Please sign in to comment.