Skip to content

gh-129033: Remove _PyInterpreterState_SetConfig() function #129048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,43 +341,6 @@ extern void _PyInterpreterState_SetWhence(

extern const PyConfig* _PyInterpreterState_GetConfig(PyInterpreterState *interp);

// Get a copy of the current interpreter configuration.
//
// Return 0 on success. Raise an exception and return -1 on error.
//
// The caller must initialize 'config', using PyConfig_InitPythonConfig()
// for example.
//
// Python must be preinitialized to call this method.
// The caller must hold the GIL.
//
// Once done with the configuration, PyConfig_Clear() must be called to clear
// it.
//
// Export for '_testinternalcapi' shared extension.
PyAPI_FUNC(int) _PyInterpreterState_GetConfigCopy(
struct PyConfig *config);

// Set the configuration of the current interpreter.
//
// This function should be called during or just after the Python
// initialization.
//
// Update the sys module with the new configuration. If the sys module was
// modified directly after the Python initialization, these changes are lost.
//
// Some configuration like faulthandler or warnoptions can be updated in the
// configuration, but don't reconfigure Python (don't enable/disable
// faulthandler and don't reconfigure warnings filters).
//
// Return 0 on success. Raise an exception and return -1 on error.
//
// The configuration should come from _PyInterpreterState_GetConfigCopy().
//
// Export for '_testinternalcapi' shared extension.
PyAPI_FUNC(int) _PyInterpreterState_SetConfig(
const struct PyConfig *config);


/*
Runtime Feature Flags
Expand Down
291 changes: 0 additions & 291 deletions Lib/test/_test_embed_set_config.py

This file was deleted.

4 changes: 2 additions & 2 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,10 @@ def requires_lzma(reason='requires lzma'):

def has_no_debug_ranges():
try:
import _testinternalcapi
import _testcapi
except ImportError:
raise unittest.SkipTest("_testinternalcapi required")
config = _testinternalcapi.get_config()
return not _testcapi.config_get('code_debug_ranges')
return not bool(config['code_debug_ranges'])

def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
Expand Down
17 changes: 8 additions & 9 deletions Lib/test/test_capi/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2141,28 +2141,27 @@ async def foo(arg): return await arg # Py 3.5
self.assertEqual(ret, 0)
self.assertEqual(pickle.load(f), {'a': '123x', 'b': '123'})

# _testcapi cannot be imported in a subinterpreter on a Free Threaded build
@support.requires_gil_enabled()
def test_py_config_isoloated_per_interpreter(self):
# A config change in one interpreter must not leak to out to others.
#
# This test could verify ANY config value, it just happens to have been
# written around the time of int_max_str_digits. Refactoring is okay.
code = """if 1:
import sys, _testinternalcapi
import sys, _testcapi

# Any config value would do, this happens to be the one being
# double checked at the time this test was written.
config = _testinternalcapi.get_config()
config['int_max_str_digits'] = 55555
config['parse_argv'] = 0
_testinternalcapi.set_config(config)
sub_value = _testinternalcapi.get_config()['int_max_str_digits']
_testcapi.config_set('int_max_str_digits', 55555)
sub_value = _testcapi.config_get('int_max_str_digits')
assert sub_value == 55555, sub_value
"""
before_config = _testinternalcapi.get_config()
assert before_config['int_max_str_digits'] != 55555
before_config = _testcapi.config_get('int_max_str_digits')
assert before_config != 55555
self.assertEqual(support.run_in_subinterp(code), 0,
'subinterp code failure, check stderr.')
after_config = _testinternalcapi.get_config()
after_config = _testcapi.config_get('int_max_str_digits')
self.assertIsNot(
before_config, after_config,
"Expected get_config() to return a new dict on each call")
Expand Down
Loading
Loading