GH-97779: Ensure that *all* frame objects are backed by "complete" frames (GH-97845)

This commit is contained in:
Brandt Bucher 2022-10-04 17:30:03 -07:00 committed by GitHub
parent c3648f4e4a
commit 0ff8fd6583
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 75 additions and 4 deletions

View file

@ -132,6 +132,7 @@ import doctest
import unittest
import textwrap
import weakref
import dis
try:
import ctypes
@ -682,6 +683,38 @@ class CodeLocationTest(unittest.TestCase):
self.check_lines(misshappen)
self.check_lines(bug93662)
@cpython_only
def test_code_new_empty(self):
# If this test fails, it means that the construction of PyCode_NewEmpty
# needs to be modified! Please update this test *and* PyCode_NewEmpty,
# so that they both stay in sync.
def f():
pass
PY_CODE_LOCATION_INFO_NO_COLUMNS = 13
f.__code__ = f.__code__.replace(
co_firstlineno=42,
co_code=bytes(
[
dis.opmap["RESUME"], 0,
dis.opmap["LOAD_ASSERTION_ERROR"], 0,
dis.opmap["RAISE_VARARGS"], 1,
]
),
co_linetable=bytes(
[
(1 << 7)
| (PY_CODE_LOCATION_INFO_NO_COLUMNS << 3)
| (3 - 1),
0,
]
),
)
self.assertRaises(AssertionError, f)
self.assertEqual(
list(f.__code__.co_positions()),
3 * [(42, 42, None, None)],
)
if check_impl_detail(cpython=True) and ctypes is not None:
py = ctypes.pythonapi