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
Next Next commit
Address review
Co-Authored-By: Mark Shannon <9448417+markshannon@users.noreply.github.com>
  • Loading branch information
Fidget-Spinner and markshannon committed Sep 3, 2025
commit bb59d45e4fd64a113552beba67ce7918b14ff51c
55 changes: 11 additions & 44 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2501,54 +2501,21 @@ def testfunc(n):
# For now... until we constant propagate it away.
self.assertIn("_BINARY_OP", uops)

def test_strip_reference_information_through_str(self):
# This test needs to be in another script due to Python's
# string interning details.
script_helper.assert_python_ok('-c', textwrap.dedent("""
import _testinternalcapi
import _opcode

def get_first_executor(func):
code = func.__code__
co_code = code.co_code
for i in range(0, len(co_code), 2):
try:
return _opcode.get_executor(code, i)
except ValueError:
pass
return None
def test_reference_tracking_across_call_doesnt_crash(self):

def iter_opnames(ex):
for item in ex:
yield item[0]
def f1():
for _ in range(TIER2_THRESHOLD + 1):
# Choose a value that won't occur elsewhere to avoid sharing
str("value that won't occur elsewhere to avoid sharing")

def get_opnames(ex):
return list(iter_opnames(ex))
f1()

def testfunc(n):
for _ in range(n):
str("abcde")


testfunc(_testinternalcapi.TIER2_THRESHOLD)
ex = get_first_executor(testfunc)
assert ex is not None
uops = get_opnames(ex)
assert "_POP_TOP_NOP" not in uops
"""))

def test_strip_reference_information_through_tuple(self):
def testfunc(n):
for _ in range(n):
tuple((1,))

testfunc(TIER2_THRESHOLD * 2)

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
def f2():
for _ in range(TIER2_THRESHOLD + 1):
# Choose a value that won't occur elsewhere to avoid sharing
tuple((31, -17, 25, "won't occur elsewhere"))

self.assertNotIn("_POP_TOP_NOP", uops)
f2()


def global_identity(x):
Expand Down