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 Jan 6, 2022
1 parent 37886c7 commit ce42116
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
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

0 comments on commit ce42116

Please sign in to comment.