From 331c4fc058055252e24101cc8b731dd4711be0a2 Mon Sep 17 00:00:00 2001
From: Jannic Warken <jannic.warken@gmail.com>
Date: Sat, 15 Jan 2022 17:07:07 +0100
Subject: [PATCH 1/2] Fix handling of NoReturn in Union

---
 mypy/checkexpr.py                | 2 ++
 test-data/unit/check-unions.test | 5 +++++
 2 files changed, 7 insertions(+)

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..9ddb32073700 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]: return 1
+reveal_type(f()) # N: Revealed type is "builtins.int"
+
 [case testUnionSimplificationGenericFunction]
 from typing import TypeVar, Union, List
 T = TypeVar('T')

From b64584bc73c683b32b194d8341ca2a2dd585b0fb Mon Sep 17 00:00:00 2001
From: Jannic Warken <jannic.warken@gmail.com>
Date: Sun, 16 Jan 2022 11:58:20 +0100
Subject: [PATCH 2/2] Update test-data/unit/check-unions.test

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
---
 test-data/unit/check-unions.test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test-data/unit/check-unions.test b/test-data/unit/check-unions.test
index 9ddb32073700..6966af289f28 100644
--- a/test-data/unit/check-unions.test
+++ b/test-data/unit/check-unions.test
@@ -146,7 +146,7 @@ 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]: return 1
+def f() -> Union[int, NoReturn]: ...
 reveal_type(f()) # N: Revealed type is "builtins.int"
 
 [case testUnionSimplificationGenericFunction]