Skip to content

Commit

Permalink
Add test for LOAD_ATTR_CLASS_WITH_METACLASS_CHECK
Browse files Browse the repository at this point in the history
  • Loading branch information
mpage committed Dec 20, 2024
1 parent fa02260 commit 47c794f
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions Lib/test/test_opcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,13 +717,10 @@ def write(items):
@requires_specialization_ft
def test_load_attr_class(self):
def get_items():
class B:
pass

class C:
# a must be set to an instance that uses deferred reference
# counting
a = B
# counting in free-threaded builds
a = type("Foo", (object,), {})

items = []
for _ in range(self.ITEMS):
Expand All @@ -744,11 +741,46 @@ def write(items):
del item.a
except AttributeError:
pass
item.a = object()
item.a = type("Foo", (object,), {})

opname = "LOAD_ATTR_CLASS"
self.assert_races_do_not_crash(opname, get_items, read, write)

@requires_specialization_ft
def test_load_attr_class_with_metaclass_check(self):
def get_items():
class Meta(type):
pass

class C(metaclass=Meta):
# a must be set to an instance that uses deferred reference
# counting in free-threaded builds
a = type("Foo", (object,), {})

items = []
for _ in range(self.ITEMS):
item = C
items.append(item)
return items

def read(items):
for item in items:
try:
item.a
except AttributeError:
pass

def write(items):
for item in items:
try:
del item.a
except AttributeError:
pass
item.a = type("Foo", (object,), {})

opname = "LOAD_ATTR_CLASS_WITH_METACLASS_CHECK"
self.assert_races_do_not_crash(opname, get_items, read, write)

@requires_specialization_ft
def test_load_attr_getattribute_overridden(self):
def get_items():
Expand Down

0 comments on commit 47c794f

Please sign in to comment.