bpo-32652: Defer pymain_set_global_config() call (#5303)

In Py_Main(), don't call pymain_set_global_config() early: only call
it when the whole configuration has been read.

Add an unit test to prevent future regression.
This commit is contained in:
Victor Stinner 2018-01-25 09:18:36 +01:00 committed by GitHub
parent cab0b2b053
commit 2b822a0bb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 14 deletions

View file

@ -223,6 +223,21 @@ class UTF8ModeTests(unittest.TestCase):
c_arg = arg_ascii
check('utf8=0', [c_arg], LC_ALL='C')
def test_optim_level(self):
# CPython: check that Py_Main() doesn't increment Py_OptimizeFlag
# twice when -X utf8 requires to parse the configuration twice (when
# the encoding changes after reading the configuration, the
# configuration is read again with the new encoding).
code = 'import sys; print(sys.flags.optimize)'
out = self.get_output('-X', 'utf8', '-O', '-c', code)
self.assertEqual(out, '1')
out = self.get_output('-X', 'utf8', '-OO', '-c', code)
self.assertEqual(out, '2')
code = 'import sys; print(sys.flags.ignore_environment)'
out = self.get_output('-X', 'utf8', '-E', '-c', code)
self.assertEqual(out, '1')
if __name__ == "__main__":
unittest.main()