@@ -1125,6 +1125,37 @@ def test_something(self):
11251125 """ )
11261126 assert_python_ok ("-c" , source )
11271127
1128+ def test_do_not_cleanup_type_subclasses_before_finalization (self ):
1129+ # https://github.com/python/cpython/issues/135552
1130+ code = textwrap .dedent ("""
1131+ class BaseNode:
1132+ def __del__(self):
1133+ BaseNode.next = BaseNode.next.next
1134+
1135+ class Node(BaseNode):
1136+ pass
1137+
1138+ BaseNode.next = Node()
1139+ BaseNode.next.next = Node()
1140+ """ )
1141+ assert_python_ok ("-c" , code )
1142+
1143+ code_inside_function = textwrap .dedent ("""
1144+ def test():
1145+ class BaseNode:
1146+ def __del__(self):
1147+ BaseNode.next = BaseNode.next.next
1148+
1149+ class Node(BaseNode):
1150+ pass
1151+
1152+ BaseNode.next = Node()
1153+ BaseNode.next.next = Node()
1154+
1155+ test()
1156+ """ )
1157+ assert_python_ok ("-c" , code_inside_function )
1158+
11281159
11291160class IncrementalGCTests (unittest .TestCase ):
11301161 @unittest .skipIf (_testinternalcapi is None , "requires _testinternalcapi" )
@@ -1517,22 +1548,6 @@ def test_ast_fini(self):
15171548 """ )
15181549 assert_python_ok ("-c" , code )
15191550
1520- def test_reset_type_cache_after_finalization (self ):
1521- # https://github.com/python/cpython/issues/135552
1522- code = textwrap .dedent ("""
1523- class BaseNode:
1524- def __del__(self):
1525- BaseNode.next = BaseNode.next.next
1526-
1527-
1528- class Node(BaseNode):
1529- pass
1530-
1531-
1532- BaseNode.next = Node()
1533- BaseNode.next.next = Node()
1534- """ )
1535- assert_python_ok ("-c" , code )
15361551
15371552
15381553def setUpModule ():
0 commit comments