gh-96512: Move int_max_str_digits setting to PyConfig (#96944)

It had to live as a global outside of PyConfig for stable ABI reasons in
the pre-3.12 backports.

This removes the `_Py_global_config_int_max_str_digits` and gets rid of
the equivalent field in the internal `struct _is PyInterpreterState` as
code can just use the existing nested config struct within that.

Adds tests to verify unique settings and configs in subinterpreters.
This commit is contained in:
Gregory P. Smith 2022-10-03 13:55:45 -07:00 committed by GitHub
parent cfbc7dd910
commit b0f89cb431
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 111 additions and 24 deletions

View file

@ -770,6 +770,26 @@ class IntStrDigitLimitsTests(unittest.TestCase):
with self.subTest(base=base):
self._other_base_helper(base)
def test_int_max_str_digits_is_per_interpreter(self):
# Changing the limit in one interpreter does not change others.
code = """if 1:
# Subinterpreters maintain and enforce their own limit
import sys
sys.set_int_max_str_digits(2323)
try:
int('3'*3333)
except ValueError:
pass
else:
raise AssertionError('Expected a int max str digits ValueError.')
"""
with support.adjust_int_max_str_digits(4000):
before_value = sys.get_int_max_str_digits()
self.assertEqual(support.run_in_subinterp(code), 0,
'subinterp code failure, check stderr.')
after_value = sys.get_int_max_str_digits()
self.assertEqual(before_value, after_value)
class IntSubclassStrDigitLimitsTests(IntStrDigitLimitsTests):
int_class = IntSubclass