diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index b05f9168ee12..ef1a94ee66dd 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -378,6 +378,8 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) -> if isinstance(e.callee, MemberExpr) and e.callee.name == 'format': self.check_str_format_call(e) ret_type = get_proper_type(ret_type) + if isinstance(ret_type, UnionType): + ret_type = make_simplified_union(ret_type.items) if isinstance(ret_type, UninhabitedType) and not ret_type.ambiguous: self.chk.binder.unreachable() # Warn on calls to functions that always return None. The check diff --git a/test-data/unit/check-unions.test b/test-data/unit/check-unions.test index cf1ff5650d49..6966af289f28 100644 --- a/test-data/unit/check-unions.test +++ b/test-data/unit/check-unions.test @@ -144,6 +144,11 @@ f(1) f(None) f('') # E: Argument 1 to "f" has incompatible type "str"; expected "Optional[int]" +[case testUnionWithNoReturn] +from typing import Union, NoReturn +def f() -> Union[int, NoReturn]: ... +reveal_type(f()) # N: Revealed type is "builtins.int" + [case testUnionSimplificationGenericFunction] from typing import TypeVar, Union, List T = TypeVar('T')