Skip to content

Commit 27ebb23

Browse files
committed
gh-129033: Remove _PyInterpreterState_SetConfig() function
Remove _PyInterpreterState_GetConfigCopy() and _PyInterpreterState_SetConfig() private functions. PEP 741 "Python Configuration C API" added a better public C API: PyConfig_Get() and PyConfig_Set().
1 parent da0f47c commit 27ebb23

File tree

11 files changed

+20
-500
lines changed

11 files changed

+20
-500
lines changed

Include/internal/pycore_interp.h

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -341,43 +341,6 @@ extern void _PyInterpreterState_SetWhence(
341341

342342
extern const PyConfig* _PyInterpreterState_GetConfig(PyInterpreterState *interp);
343343

344-
// Get a copy of the current interpreter configuration.
345-
//
346-
// Return 0 on success. Raise an exception and return -1 on error.
347-
//
348-
// The caller must initialize 'config', using PyConfig_InitPythonConfig()
349-
// for example.
350-
//
351-
// Python must be preinitialized to call this method.
352-
// The caller must hold the GIL.
353-
//
354-
// Once done with the configuration, PyConfig_Clear() must be called to clear
355-
// it.
356-
//
357-
// Export for '_testinternalcapi' shared extension.
358-
PyAPI_FUNC(int) _PyInterpreterState_GetConfigCopy(
359-
struct PyConfig *config);
360-
361-
// Set the configuration of the current interpreter.
362-
//
363-
// This function should be called during or just after the Python
364-
// initialization.
365-
//
366-
// Update the sys module with the new configuration. If the sys module was
367-
// modified directly after the Python initialization, these changes are lost.
368-
//
369-
// Some configuration like faulthandler or warnoptions can be updated in the
370-
// configuration, but don't reconfigure Python (don't enable/disable
371-
// faulthandler and don't reconfigure warnings filters).
372-
//
373-
// Return 0 on success. Raise an exception and return -1 on error.
374-
//
375-
// The configuration should come from _PyInterpreterState_GetConfigCopy().
376-
//
377-
// Export for '_testinternalcapi' shared extension.
378-
PyAPI_FUNC(int) _PyInterpreterState_SetConfig(
379-
const struct PyConfig *config);
380-
381344

382345
/*
383346
Runtime Feature Flags

Lib/test/_test_embed_set_config.py

Lines changed: 0 additions & 291 deletions
This file was deleted.

Lib/test/support/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,10 @@ def requires_lzma(reason='requires lzma'):
505505

506506
def has_no_debug_ranges():
507507
try:
508-
import _testinternalcapi
508+
import _testcapi
509509
except ImportError:
510510
raise unittest.SkipTest("_testinternalcapi required")
511-
config = _testinternalcapi.get_config()
511+
return not _testcapi.config_get('code_debug_ranges')
512512
return not bool(config['code_debug_ranges'])
513513

514514
def requires_debug_ranges(reason='requires co_positions / debug_ranges'):

Lib/test/test_capi/test_misc.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,22 +2147,19 @@ def test_py_config_isoloated_per_interpreter(self):
21472147
# This test could verify ANY config value, it just happens to have been
21482148
# written around the time of int_max_str_digits. Refactoring is okay.
21492149
code = """if 1:
2150-
import sys, _testinternalcapi
2150+
import sys, _testcapi
21512151
21522152
# Any config value would do, this happens to be the one being
21532153
# double checked at the time this test was written.
2154-
config = _testinternalcapi.get_config()
2155-
config['int_max_str_digits'] = 55555
2156-
config['parse_argv'] = 0
2157-
_testinternalcapi.set_config(config)
2158-
sub_value = _testinternalcapi.get_config()['int_max_str_digits']
2154+
_testcapi.config_set('int_max_str_digits', 55555)
2155+
sub_value = _testcapi.config_get('int_max_str_digits')
21592156
assert sub_value == 55555, sub_value
21602157
"""
2161-
before_config = _testinternalcapi.get_config()
2162-
assert before_config['int_max_str_digits'] != 55555
2158+
before_config = _testcapi.config_get('int_max_str_digits')
2159+
assert before_config != 55555
21632160
self.assertEqual(support.run_in_subinterp(code), 0,
21642161
'subinterp code failure, check stderr.')
2165-
after_config = _testinternalcapi.get_config()
2162+
after_config = _testcapi.config_get('int_max_str_digits')
21662163
self.assertIsNot(
21672164
before_config, after_config,
21682165
"Expected get_config() to return a new dict on each call")

0 commit comments

Comments
 (0)