File workaround-parenthesized-context-managers.patch of Package python-mypy

From fb610cb043ea990046d3665ac39238d5223e3eb3 Mon Sep 17 00:00:00 2001
From: hauntsaninja <hauntsaninja@gmail.com>
Date: Sun, 25 Feb 2024 14:01:07 -0800
Subject: [PATCH 1/4] Workaround parenthesised context manager issue

Fixes #16945
---
 mypy/checker.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/mypy/checker.py b/mypy/checker.py
index 56be3db3f9e7..5081265c9cac 100644
--- a/mypy/checker.py
+++ b/mypy/checker.py
@@ -526,16 +526,18 @@ def check_second_pass(
                     # print("XXX in pass %d, class %s, function %s" %
                     #       (self.pass_num, type_name, node.fullname or node.name))
                     done.add(node)
-                    with (
+                    tscope_class_ctx = (
                         self.tscope.class_scope(active_typeinfo)
                         if active_typeinfo
                         else nullcontext()
-                    ):
-                        with (
+                    )
+                    with tscope_class_ctx:
+                        checker_scope_class_ctx = (
                             self.scope.push_class(active_typeinfo)
                             if active_typeinfo
                             else nullcontext()
-                        ):
+                        )
+                        with checker_scope_class_ctx:
                             self.check_partial(node)
             return True
 

From 4c9d637919ef5262b94d6dc160f63d12bd126167 Mon Sep 17 00:00:00 2001
From: hauntsaninja <hauntsaninja@gmail.com>
Date: Sun, 25 Feb 2024 14:14:56 -0800
Subject: [PATCH 2/4] .

---
 mypy/checker.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mypy/checker.py b/mypy/checker.py
index 5081265c9cac..426e5a805893 100644
--- a/mypy/checker.py
+++ b/mypy/checker.py
@@ -526,6 +526,7 @@ def check_second_pass(
                     # print("XXX in pass %d, class %s, function %s" %
                     #       (self.pass_num, type_name, node.fullname or node.name))
                     done.add(node)
+                    # Alias context managers to work around https://github.com/python/cpython/issues/115881
                     tscope_class_ctx = (
                         self.tscope.class_scope(active_typeinfo)
                         if active_typeinfo

From 9e33616ec8405b4e3c3b345c8461e77c4786a22c Mon Sep 17 00:00:00 2001
From: hauntsaninja <hauntsaninja@gmail.com>
Date: Sun, 25 Feb 2024 14:18:34 -0800
Subject: [PATCH 3/4] .

---
 mypy/checker.py | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/mypy/checker.py b/mypy/checker.py
index 426e5a805893..d60f223036ea 100644
--- a/mypy/checker.py
+++ b/mypy/checker.py
@@ -4,7 +4,7 @@
 
 import itertools
 from collections import defaultdict
-from contextlib import contextmanager, nullcontext
+from contextlib import contextmanager, ExitStack
 from typing import (
     AbstractSet,
     Callable,
@@ -526,20 +526,11 @@ def check_second_pass(
                     # print("XXX in pass %d, class %s, function %s" %
                     #       (self.pass_num, type_name, node.fullname or node.name))
                     done.add(node)
-                    # Alias context managers to work around https://github.com/python/cpython/issues/115881
-                    tscope_class_ctx = (
-                        self.tscope.class_scope(active_typeinfo)
-                        if active_typeinfo
-                        else nullcontext()
-                    )
-                    with tscope_class_ctx:
-                        checker_scope_class_ctx = (
-                            self.scope.push_class(active_typeinfo)
-                            if active_typeinfo
-                            else nullcontext()
-                        )
-                        with checker_scope_class_ctx:
-                            self.check_partial(node)
+                    with ExitStack() as stack:
+                        if active_typeinfo:
+                            stack.enter_context(self.tscope.class_scope(active_typeinfo))
+                            stack.enter_context(self.scope.push_class(active_typeinfo))
+                        self.check_partial(node)
             return True
 
     def check_partial(self, node: DeferredNodeType | FineGrainedDeferredNodeType) -> None:

From f7f9f114451065a27a7d0d734ea38f1b80a965df Mon Sep 17 00:00:00 2001
From: hauntsaninja <hauntsaninja@gmail.com>
Date: Sun, 25 Feb 2024 14:18:46 -0800
Subject: [PATCH 4/4] .

---
 mypy/checker.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mypy/checker.py b/mypy/checker.py
index d60f223036ea..9f987cb5ccdf 100644
--- a/mypy/checker.py
+++ b/mypy/checker.py
@@ -4,7 +4,7 @@
 
 import itertools
 from collections import defaultdict
-from contextlib import contextmanager, ExitStack
+from contextlib import ExitStack, contextmanager
 from typing import (
     AbstractSet,
     Callable,
openSUSE Build Service is sponsored by