@@ -564,6 +564,16 @@ def instantiate():
564564 instantiate ()
565565
566566
567+ def make_deferred_ref_count_obj ():
568+ """Create an object that uses deferred reference counting.
569+
570+ Only objects that use deferred refence counting may be stored in inline
571+ caches in free-threaded builds. This constructs a new class named Foo,
572+ which uses deferred reference counting.
573+ """
574+ return type ("Foo" , (object ,), {})
575+
576+
567577@threading_helper .requires_working_threading ()
568578class TestRacesDoNotCrash (TestBase ):
569579 # Careful with these. Bigger numbers have a higher chance of catching bugs,
@@ -718,9 +728,7 @@ def write(items):
718728 def test_load_attr_class (self ):
719729 def get_items ():
720730 class C :
721- # a must be set to an instance that uses deferred reference
722- # counting in free-threaded builds
723- a = type ("Foo" , (object ,), {})
731+ a = make_deferred_ref_count_obj ()
724732
725733 items = []
726734 for _ in range (self .ITEMS ):
@@ -741,7 +749,7 @@ def write(items):
741749 del item .a
742750 except AttributeError :
743751 pass
744- item .a = type ( "Foo" , ( object ,), {} )
752+ item .a = make_deferred_ref_count_obj ( )
745753
746754 opname = "LOAD_ATTR_CLASS"
747755 self .assert_races_do_not_crash (opname , get_items , read , write )
@@ -753,9 +761,7 @@ class Meta(type):
753761 pass
754762
755763 class C (metaclass = Meta ):
756- # a must be set to an instance that uses deferred reference
757- # counting in free-threaded builds
758- a = type ("Foo" , (object ,), {})
764+ a = make_deferred_ref_count_obj ()
759765
760766 items = []
761767 for _ in range (self .ITEMS ):
@@ -776,7 +782,7 @@ def write(items):
776782 del item .a
777783 except AttributeError :
778784 pass
779- item .a = type ( "Foo" , ( object ,), {} )
785+ item .a = make_deferred_ref_count_obj ( )
780786
781787 opname = "LOAD_ATTR_CLASS_WITH_METACLASS_CHECK"
782788 self .assert_races_do_not_crash (opname , get_items , read , write )
0 commit comments