|
142 | 142 | from test.support import (cpython_only,
|
143 | 143 | check_impl_detail, requires_debug_ranges,
|
144 | 144 | gc_collect, Py_GIL_DISABLED,
|
145 |
| - suppress_immortalization) |
| 145 | + suppress_immortalization, |
| 146 | + skip_if_suppress_immortalization) |
146 | 147 | from test.support.script_helper import assert_python_ok
|
147 | 148 | from test.support import threading_helper, import_helper
|
148 | 149 | from test.support.bytecode_helper import instructions_with_positions
|
@@ -570,11 +571,31 @@ def f(a='str_value'):
|
570 | 571 | self.assertIsInterned(f())
|
571 | 572 |
|
572 | 573 | @cpython_only
|
| 574 | + @unittest.skipIf(Py_GIL_DISABLED, "free-threaded build interns all string constants") |
573 | 575 | def test_interned_string_with_null(self):
|
574 | 576 | co = compile(r'res = "str\0value!"', '?', 'exec')
|
575 | 577 | v = self.find_const(co.co_consts, 'str\0value!')
|
576 | 578 | self.assertIsNotInterned(v)
|
577 | 579 |
|
| 580 | + @cpython_only |
| 581 | + @unittest.skipUnless(Py_GIL_DISABLED, "does not intern all constants") |
| 582 | + @skip_if_suppress_immortalization() |
| 583 | + def test_interned_constants(self): |
| 584 | + # compile separately to avoid compile time de-duping |
| 585 | + |
| 586 | + globals = {} |
| 587 | + exec(textwrap.dedent(""" |
| 588 | + def func1(): |
| 589 | + return (0.0, (1, 2, "hello")) |
| 590 | + """), globals) |
| 591 | + |
| 592 | + exec(textwrap.dedent(""" |
| 593 | + def func2(): |
| 594 | + return (0.0, (1, 2, "hello")) |
| 595 | + """), globals) |
| 596 | + |
| 597 | + self.assertTrue(globals["func1"]() is globals["func2"]()) |
| 598 | + |
578 | 599 |
|
579 | 600 | class CodeWeakRefTest(unittest.TestCase):
|
580 | 601 |
|
|
0 commit comments