Skip to content

gh-113937 Fix failures in type cache tests due to re-running #113953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Lib/test/test_type_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class C:

type_assign_version(C)
orig_version = type_get_version(C)
self.assertNotEqual(orig_version, 0)
if orig_version == 0:
self.skipTest("Could not assign a valid type version")

type_modified(C)
type_assign_specific_version_unsafe(C, orig_version + 5)
Expand All @@ -84,10 +85,11 @@ class TypeCacheWithSpecializationTests(unittest.TestCase):
def tearDown(self):
_clear_type_cache()

def _assign_and_check_valid_version(self, user_type):
type_modified(user_type)
type_assign_version(user_type)
self.assertNotEqual(type_get_version(user_type), 0)
def _assign_valid_version_or_skip(self, type_):
type_modified(type_)
type_assign_version(type_)
if type_get_version(type_) == 0:
self.skipTest("Could not assign valid type version")

def _assign_and_check_version_0(self, user_type):
type_modified(user_type)
Expand All @@ -98,8 +100,6 @@ def _all_opnames(self, func):
return set(instr.opname for instr in dis.Bytecode(func, adaptive=True))

def _check_specialization(self, func, arg, opname, *, should_specialize):
self.assertIn(opname, self._all_opnames(func))

for _ in range(100):
func(arg)

Expand All @@ -113,7 +113,7 @@ class A:
def foo(self):
pass

self._assign_and_check_valid_version(A)
self._assign_valid_version_or_skip(A)

def load_foo_1(type_):
type_.foo
Expand All @@ -129,8 +129,8 @@ def load_foo_2(type_):
self._check_specialization(load_foo_2, A, "LOAD_ATTR", should_specialize=False)

def test_class_load_attr_specialization_static_type(self):
self._assign_and_check_valid_version(str)
self._assign_and_check_valid_version(bytes)
self._assign_valid_version_or_skip(str)
self._assign_valid_version_or_skip(bytes)

def get_capitalize_1(type_):
return type_.capitalize
Expand Down Expand Up @@ -164,7 +164,7 @@ class G:
def x(self):
return 9

self._assign_and_check_valid_version(G)
self._assign_valid_version_or_skip(G)

def load_x_1(instance):
instance.x
Expand All @@ -183,7 +183,7 @@ def test_store_attr_specialization_user_type(self):
class B:
__slots__ = ("bar",)

self._assign_and_check_valid_version(B)
self._assign_valid_version_or_skip(B)

def store_bar_1(type_):
type_.bar = 10
Expand All @@ -203,7 +203,7 @@ class F:
def __init__(self):
pass

self._assign_and_check_valid_version(F)
self._assign_valid_version_or_skip(F)

def call_class_1(type_):
type_()
Expand All @@ -222,7 +222,7 @@ def test_to_bool_specialization_user_type(self):
class H:
pass

self._assign_and_check_valid_version(H)
self._assign_valid_version_or_skip(H)

def to_bool_1(instance):
not instance
Expand Down