137137except ImportError :
138138 ctypes = None
139139from test .support import (run_doctest , run_unittest , cpython_only ,
140- check_impl_detail )
140+ check_impl_detail , requires_debug_ranges )
141+ from test .support .script_helper import assert_python_ok
141142
142143
143144def consts (t ):
@@ -325,6 +326,7 @@ def func():
325326 new_code = code = func .__code__ .replace (co_linetable = b'' )
326327 self .assertEqual (list (new_code .co_lines ()), [])
327328
329+ @requires_debug_ranges ()
328330 def test_co_positions_artificial_instructions (self ):
329331 import dis
330332
@@ -372,8 +374,32 @@ def test_co_positions_artificial_instructions(self):
372374 ]
373375 )
374376
377+ def test_endline_and_columntable_none_when_no_debug_ranges (self ):
378+ # Make sure that if `-X no_debug_ranges` is used, the endlinetable and
379+ # columntable are None.
380+ code = textwrap .dedent ("""
381+ def f():
382+ pass
383+
384+ assert f.__code__.co_endlinetable is None
385+ assert f.__code__.co_columntable is None
386+ """ )
387+ assert_python_ok ('-X' , 'no_debug_ranges' , '-c' , code , __cleanenv = True )
388+
389+ def test_endline_and_columntable_none_when_no_debug_ranges_env (self ):
390+ # Same as above but using the environment variable opt out.
391+ code = textwrap .dedent ("""
392+ def f():
393+ pass
394+
395+ assert f.__code__.co_endlinetable is None
396+ assert f.__code__.co_columntable is None
397+ """ )
398+ assert_python_ok ('-c' , code , PYTHONNODEBUGRANGES = '1' , __cleanenv = True )
399+
375400 # co_positions behavior when info is missing.
376401
402+ @requires_debug_ranges ()
377403 def test_co_positions_empty_linetable (self ):
378404 def func ():
379405 x = 1
@@ -382,6 +408,7 @@ def func():
382408 self .assertIsNone (line )
383409 self .assertEqual (end_line , new_code .co_firstlineno + 1 )
384410
411+ @requires_debug_ranges ()
385412 def test_co_positions_empty_endlinetable (self ):
386413 def func ():
387414 x = 1
@@ -390,6 +417,7 @@ def func():
390417 self .assertEqual (line , new_code .co_firstlineno + 1 )
391418 self .assertIsNone (end_line )
392419
420+ @requires_debug_ranges ()
393421 def test_co_positions_empty_columntable (self ):
394422 def func ():
395423 x = 1
0 commit comments