[Python-checkins] bpo-45954: Rename PyConfig.no_debug_ranges to code_debug_ranges (GH-29886)

vstinner webhook-mailer at python.org
Thu Dec 2 05:43:42 EST 2021


https://github.com/python/cpython/commit/a6c3b0faa1d55e36539caf19bd3bcf1dea12df84
commit: a6c3b0faa1d55e36539caf19bd3bcf1dea12df84
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2021-12-02T11:43:37+01:00
summary:

bpo-45954: Rename PyConfig.no_debug_ranges to code_debug_ranges (GH-29886)

Rename PyConfig.no_debug_ranges to PyConfig.code_debug_ranges and
invert the value.

Document -X no_debug_ranges and PYTHONNODEBUGRANGES env var in
PyConfig.code_debug_ranges documentation.

files:
M Doc/c-api/init_config.rst
M Include/cpython/initconfig.h
M Lib/test/_test_embed_set_config.py
M Lib/test/support/__init__.py
M Lib/test/test_embed.py
M Objects/codeobject.c
M Programs/_testembed.c
M Python/initconfig.c

diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst
index 989660caeda06..3642a8bf7fbc7 100644
--- a/Doc/c-api/init_config.rst
+++ b/Doc/c-api/init_config.rst
@@ -596,13 +596,16 @@ PyConfig
 
       .. versionadded:: 3.10
 
-   .. c:member:: int no_debug_ranges
+   .. c:member:: int code_debug_ranges
 
-      If equals to ``1``, disables the inclusion of the end line and column
+      If equals to ``0``, disables the inclusion of the end line and column
       mappings in code objects. Also disables traceback printing carets to
       specific error locations.
 
-      Default: ``0``.
+      Set to ``0`` by the :envvar:`PYTHONNODEBUGRANGES` environment variable
+      and by the :option:`-X no_debug_ranges <-X>` command line option.
+
+      Default: ``1``.
 
       .. versionadded:: 3.11
 
diff --git a/Include/cpython/initconfig.h b/Include/cpython/initconfig.h
index 76f3c5268ee5f..2be4c25ec0b09 100644
--- a/Include/cpython/initconfig.h
+++ b/Include/cpython/initconfig.h
@@ -143,7 +143,7 @@ typedef struct PyConfig {
     int faulthandler;
     int tracemalloc;
     int import_time;
-    int no_debug_ranges;
+    int code_debug_ranges;
     int show_ref_count;
     int dump_refs;
     wchar_t *dump_refs_file;
diff --git a/Lib/test/_test_embed_set_config.py b/Lib/test/_test_embed_set_config.py
index 23c927e2646bc..d05907ecfe744 100644
--- a/Lib/test/_test_embed_set_config.py
+++ b/Lib/test/_test_embed_set_config.py
@@ -1,7 +1,7 @@
 # bpo-42260: Test _PyInterpreterState_GetConfigCopy()
 # and _PyInterpreterState_SetConfig().
 #
-# Test run in a subinterpreter since set_config(get_config())
+# Test run in a subprocess since set_config(get_config())
 # does reset sys attributes to their state of the Python startup
 # (before the site module is run).
 
@@ -61,7 +61,7 @@ def test_set_invalid(self):
             'faulthandler',
             'tracemalloc',
             'import_time',
-            'no_debug_ranges',
+            'code_debug_ranges',
             'show_ref_count',
             'dump_refs',
             'malloc_stats',
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 6d84a8bea420e..f8faa41ad439c 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -449,7 +449,7 @@ def has_no_debug_ranges():
     except ImportError:
         raise unittest.SkipTest("_testinternalcapi required")
     config = _testinternalcapi.get_config()
-    return bool(config['no_debug_ranges'])
+    return not bool(config['code_debug_ranges'])
 
 def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
     return unittest.skipIf(has_no_debug_ranges(), reason)
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index 94cdd98b2dbba..4781c7f2a9d12 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -386,7 +386,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
         'faulthandler': 0,
         'tracemalloc': 0,
         'import_time': 0,
-        'no_debug_ranges': 0,
+        'code_debug_ranges': 1,
         'show_ref_count': 0,
         'dump_refs': 0,
         'malloc_stats': 0,
@@ -818,7 +818,7 @@ def test_init_from_config(self):
             'hash_seed': 123,
             'tracemalloc': 2,
             'import_time': 1,
-            'no_debug_ranges': 1,
+            'code_debug_ranges': 0,
             'show_ref_count': 1,
             'malloc_stats': 1,
 
@@ -878,7 +878,7 @@ def test_init_compat_env(self):
             'hash_seed': 42,
             'tracemalloc': 2,
             'import_time': 1,
-            'no_debug_ranges': 1,
+            'code_debug_ranges': 0,
             'malloc_stats': 1,
             'inspect': 1,
             'optimization_level': 2,
@@ -908,7 +908,7 @@ def test_init_python_env(self):
             'hash_seed': 42,
             'tracemalloc': 2,
             'import_time': 1,
-            'no_debug_ranges': 1,
+            'code_debug_ranges': 0,
             'malloc_stats': 1,
             'inspect': 1,
             'optimization_level': 2,
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 5ab8641a17caa..a413b183be8ed 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -381,7 +381,7 @@ _PyCode_New(struct _PyCodeConstructor *con)
 
     // Discard the endlinetable and columntable if we are opted out of debug
     // ranges.
-    if (_Py_GetConfig()->no_debug_ranges) {
+    if (!_Py_GetConfig()->code_debug_ranges) {
         con->endlinetable = Py_None;
         con->columntable = Py_None;
     }
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index 8077c470c07c5..fc5f44d5eb626 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -531,7 +531,7 @@ static int test_init_from_config(void)
     config.import_time = 1;
 
     putenv("PYTHONNODEBUGRANGES=0");
-    config.no_debug_ranges = 1;
+    config.code_debug_ranges = 0;
 
     config.show_ref_count = 1;
     /* FIXME: test dump_refs: bpo-34223 */
diff --git a/Python/initconfig.c b/Python/initconfig.c
index c916e2f7c0714..53b624fdd72ec 100644
--- a/Python/initconfig.c
+++ b/Python/initconfig.c
@@ -614,7 +614,7 @@ config_check_consistency(const PyConfig *config)
     assert(config->faulthandler >= 0);
     assert(config->tracemalloc >= 0);
     assert(config->import_time >= 0);
-    assert(config->no_debug_ranges >= 0);
+    assert(config->code_debug_ranges >= 0);
     assert(config->show_ref_count >= 0);
     assert(config->dump_refs >= 0);
     assert(config->malloc_stats >= 0);
@@ -740,6 +740,7 @@ _PyConfig_InitCompatConfig(PyConfig *config)
     config->legacy_windows_stdio = -1;
 #endif
     config->use_frozen_modules = -1;
+    config->code_debug_ranges = 1;
 }
 
 
@@ -904,7 +905,7 @@ _PyConfig_Copy(PyConfig *config, const PyConfig *config2)
     COPY_ATTR(faulthandler);
     COPY_ATTR(tracemalloc);
     COPY_ATTR(import_time);
-    COPY_ATTR(no_debug_ranges);
+    COPY_ATTR(code_debug_ranges);
     COPY_ATTR(show_ref_count);
     COPY_ATTR(dump_refs);
     COPY_ATTR(dump_refs_file);
@@ -1012,7 +1013,7 @@ _PyConfig_AsDict(const PyConfig *config)
     SET_ITEM_INT(faulthandler);
     SET_ITEM_INT(tracemalloc);
     SET_ITEM_INT(import_time);
-    SET_ITEM_INT(no_debug_ranges);
+    SET_ITEM_INT(code_debug_ranges);
     SET_ITEM_INT(show_ref_count);
     SET_ITEM_INT(dump_refs);
     SET_ITEM_INT(malloc_stats);
@@ -1291,7 +1292,7 @@ _PyConfig_FromDict(PyConfig *config, PyObject *dict)
     GET_UINT(faulthandler);
     GET_UINT(tracemalloc);
     GET_UINT(import_time);
-    GET_UINT(no_debug_ranges);
+    GET_UINT(code_debug_ranges);
     GET_UINT(show_ref_count);
     GET_UINT(dump_refs);
     GET_UINT(malloc_stats);
@@ -1853,7 +1854,7 @@ config_read_complex_options(PyConfig *config)
 
     if (config_get_env(config, "PYTHONNODEBUGRANGES")
        || config_get_xoption(config, L"no_debug_ranges")) {
-        config->no_debug_ranges = 1;
+        config->code_debug_ranges = 0;
     }
 
     PyStatus status;



More information about the Python-checkins mailing list