[3.14] gh-132775: Use _PyCode GetScriptXIData() (gh-134515)

(cherry picked from commit 09e72cf091, AKA gh-134511)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-05-22 17:07:11 +02:00 committed by GitHub
parent c31b25c705
commit bbf8048c0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 106 additions and 242 deletions

View file

@ -474,13 +474,15 @@ def setUp(self):
def test_signatures(self):
# See https://github.com/python/cpython/issues/126654
msg = "expected 'shared' to be a dict"
msg = r'_interpreters.exec\(\) argument 3 must be dict, not int'
with self.assertRaisesRegex(TypeError, msg):
_interpreters.exec(self.id, 'a', 1)
with self.assertRaisesRegex(TypeError, msg):
_interpreters.exec(self.id, 'a', shared=1)
msg = r'_interpreters.run_string\(\) argument 3 must be dict, not int'
with self.assertRaisesRegex(TypeError, msg):
_interpreters.run_string(self.id, 'a', shared=1)
msg = r'_interpreters.run_func\(\) argument 3 must be dict, not int'
with self.assertRaisesRegex(TypeError, msg):
_interpreters.run_func(self.id, lambda: None, shared=1)
@ -952,7 +954,8 @@ def test_invalid_syntax(self):
""")
with self.subTest('script'):
self.assert_run_failed(SyntaxError, script)
with self.assertRaises(SyntaxError):
_interpreters.run_string(self.id, script)
with self.subTest('module'):
modname = 'spam_spam_spam'
@ -1019,12 +1022,19 @@ def script():
with open(w, 'w', encoding="utf-8") as spipe:
with contextlib.redirect_stdout(spipe):
print('it worked!', end='')
failed = None
def f():
_interpreters.set___main___attrs(self.id, dict(w=w))
_interpreters.run_func(self.id, script)
nonlocal failed
try:
_interpreters.set___main___attrs(self.id, dict(w=w))
_interpreters.run_func(self.id, script)
except Exception as exc:
failed = exc
t = threading.Thread(target=f)
t.start()
t.join()
if failed:
raise Exception from failed
with open(r, encoding="utf-8") as outfile:
out = outfile.read()
@ -1053,19 +1063,16 @@ def test_closure(self):
spam = True
def script():
assert spam
with self.assertRaises(TypeError):
with self.assertRaises(ValueError):
_interpreters.run_func(self.id, script)
# XXX This hasn't been fixed yet.
@unittest.expectedFailure
def test_return_value(self):
def script():
return 'spam'
with self.assertRaises(ValueError):
_interpreters.run_func(self.id, script)
@unittest.skip("we're not quite there yet")
# @unittest.skip("we're not quite there yet")
def test_args(self):
with self.subTest('args'):
def script(a, b=0):