summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-07-11 16:15:30 (GMT)
committerGitHub <noreply@github.com>2023-07-11 16:15:30 (GMT)
commit58f9c8889d8fa79d617fddf6cb48942d3003c7fd (patch)
treee1b027f68d2fc2d3320359c366d186f827e5155b /Lib
parent60150590c74ff397ed07ef7bd752ad2f1d5cfde5 (diff)
downloadcpython-58f9c8889d8fa79d617fddf6cb48942d3003c7fd.zip
cpython-58f9c8889d8fa79d617fddf6cb48942d3003c7fd.tar.gz
cpython-58f9c8889d8fa79d617fddf6cb48942d3003c7fd.tar.bz2
[3.12] gh-106403: Restore weakref support for TypeVar and friends (GH-106418) (#106635)
gh-106403: Restore weakref support for TypeVar and friends (GH-106418) (cherry picked from commit 945d3cbf2e8e756ed16c3ec51106e6157abb2698) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_type_params.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_type_params.py b/Lib/test/test_type_params.py
index 3026cc2..bced641 100644
--- a/Lib/test/test_type_params.py
+++ b/Lib/test/test_type_params.py
@@ -3,6 +3,7 @@ import textwrap
import types
import unittest
import pickle
+import weakref
from test.support import requires_working_socket, check_syntax_error, run_code
from typing import Generic, Sequence, TypeVar, TypeVarTuple, ParamSpec, get_args
@@ -921,3 +922,33 @@ class TypeParamsPickleTest(unittest.TestCase):
# These instances are not equal,
# but class check is good enough:
self.assertIsInstance(pickle.loads(pickled), real_class)
+
+
+class TypeParamsWeakRefTest(unittest.TestCase):
+ def test_weakrefs(self):
+ T = TypeVar('T')
+ P = ParamSpec('P')
+ class OldStyle(Generic[T]):
+ pass
+
+ class NewStyle[T]:
+ pass
+
+ cases = [
+ T,
+ TypeVar('T', bound=int),
+ P,
+ P.args,
+ P.kwargs,
+ TypeVarTuple('Ts'),
+ OldStyle,
+ OldStyle[int],
+ OldStyle(),
+ NewStyle,
+ NewStyle[int],
+ NewStyle(),
+ Generic[T],
+ ]
+ for case in cases:
+ with self.subTest(case=case):
+ weakref.ref(case)