Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
add tests
  • Loading branch information
Fidget-Spinner committed Apr 12, 2026
commit a459c25bd8c2a626bdd9a28e79b8ffcb1e92773c
40 changes: 40 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,42 @@ def testfunc(n):
# __init__ resolution allows promotion of range to constant
self.assertNotIn("_LOAD_GLOBAL_BUILTINS", uops)

def test_init_guards_removed(self):
class MyPoint:
def __init__(self, x, y):
return None

def testfunc(n):
point_local = MyPoint
for _ in range(n):
p = point_local(1.0, 2.0)
p = point_local(1.0, 2.0)

_, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
self.assertIsNotNone(ex)
# The __init__ call should be traced through via _PUSH_FRAME
count = count_ops(ex, "_CREATE_INIT_FRAME")
self.assertEqual(count, 2)
# __init__ resolution allows promotion of range to constant
count = count_ops(ex, "_CHECK_OBJECT")
self.assertEqual(count, 1)

def test_init_guards_removed_global(self):

def testfunc(n):
for _ in range(n):
p = MyGlobalPoint(1.0, 2.0)
p = MyGlobalPoint(1.0, 2.0)

_, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
self.assertIsNotNone(ex)
# The __init__ call should be traced through via _PUSH_FRAME
count = count_ops(ex, "_CREATE_INIT_FRAME")
self.assertEqual(count, 2)
# __init__ resolution allows promotion of range to constant
count = count_ops(ex, "_CHECK_OBJECT")
self.assertEqual(count, 0)

def test_guard_type_version_locked_propagates(self):
"""
_GUARD_TYPE_VERSION_LOCKED should set the type version on the
Expand Down Expand Up @@ -5216,5 +5252,9 @@ def test(self, *args, **kwargs):
test_object = TestObject()
test_bound_method = TestObject.test.__get__(test_object)

class MyGlobalPoint:
def __init__(self, x, y):
return None

if __name__ == "__main__":
unittest.main()
Loading