mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
bpo-43950: Add option to opt-out of PEP-657 (GH-27023)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com> Co-authored-by: Batuhan Taskaya <batuhanosmantaskaya@gmail.com> Co-authored-by: Ammar Askar <ammar@ammaraskar.com>
This commit is contained in:
parent
3d3027c5fc
commit
4823d9a512
18 changed files with 276 additions and 64 deletions
|
@ -137,7 +137,8 @@ try:
|
|||
except ImportError:
|
||||
ctypes = None
|
||||
from test.support import (run_doctest, run_unittest, cpython_only,
|
||||
check_impl_detail)
|
||||
check_impl_detail, requires_debug_ranges)
|
||||
from test.support.script_helper import assert_python_ok
|
||||
|
||||
|
||||
def consts(t):
|
||||
|
@ -325,6 +326,7 @@ class CodeTest(unittest.TestCase):
|
|||
new_code = code = func.__code__.replace(co_linetable=b'')
|
||||
self.assertEqual(list(new_code.co_lines()), [])
|
||||
|
||||
@requires_debug_ranges()
|
||||
def test_co_positions_artificial_instructions(self):
|
||||
import dis
|
||||
|
||||
|
@ -372,8 +374,32 @@ class CodeTest(unittest.TestCase):
|
|||
]
|
||||
)
|
||||
|
||||
def test_endline_and_columntable_none_when_no_debug_ranges(self):
|
||||
# Make sure that if `-X no_debug_ranges` is used, the endlinetable and
|
||||
# columntable are None.
|
||||
code = textwrap.dedent("""
|
||||
def f():
|
||||
pass
|
||||
|
||||
assert f.__code__.co_endlinetable is None
|
||||
assert f.__code__.co_columntable is None
|
||||
""")
|
||||
assert_python_ok('-X', 'no_debug_ranges', '-c', code, __cleanenv=True)
|
||||
|
||||
def test_endline_and_columntable_none_when_no_debug_ranges_env(self):
|
||||
# Same as above but using the environment variable opt out.
|
||||
code = textwrap.dedent("""
|
||||
def f():
|
||||
pass
|
||||
|
||||
assert f.__code__.co_endlinetable is None
|
||||
assert f.__code__.co_columntable is None
|
||||
""")
|
||||
assert_python_ok('-c', code, PYTHONNODEBUGRANGES='1', __cleanenv=True)
|
||||
|
||||
# co_positions behavior when info is missing.
|
||||
|
||||
@requires_debug_ranges()
|
||||
def test_co_positions_empty_linetable(self):
|
||||
def func():
|
||||
x = 1
|
||||
|
@ -382,6 +408,7 @@ class CodeTest(unittest.TestCase):
|
|||
self.assertIsNone(line)
|
||||
self.assertEqual(end_line, new_code.co_firstlineno + 1)
|
||||
|
||||
@requires_debug_ranges()
|
||||
def test_co_positions_empty_endlinetable(self):
|
||||
def func():
|
||||
x = 1
|
||||
|
@ -390,6 +417,7 @@ class CodeTest(unittest.TestCase):
|
|||
self.assertEqual(line, new_code.co_firstlineno + 1)
|
||||
self.assertIsNone(end_line)
|
||||
|
||||
@requires_debug_ranges()
|
||||
def test_co_positions_empty_columntable(self):
|
||||
def func():
|
||||
x = 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue