Skip to content

Commit

Permalink
Handle NoReturn type aliases (python#11912)
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn authored and tushar-deepsource committed Jan 20, 2022
1 parent d13a62f commit e13b9af
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 @@ -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
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 e13b9af

Please sign in to comment.