gh-76785: Return an "excinfo" Object From Interpreter.run() (gh-111573)

This commit is contained in:
Eric Snow 2023-11-22 17:55:00 -07:00 committed by GitHub
parent 14e539f097
commit 9e56eedd01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 433 additions and 258 deletions

View file

@ -655,25 +655,19 @@ class MagicNumberTests(unittest.TestCase):
@unittest.skipIf(_interpreters is None, 'subinterpreters required')
class IncompatibleExtensionModuleRestrictionsTests(unittest.TestCase):
ERROR = re.compile("^ImportError: module (.*) does not support loading in subinterpreters")
def run_with_own_gil(self, script):
interpid = _interpreters.create(isolated=True)
try:
_interpreters.run_string(interpid, script)
except _interpreters.RunFailedError as exc:
if m := self.ERROR.match(str(exc)):
modname, = m.groups()
raise ImportError(modname)
excsnap = _interpreters.run_string(interpid, script)
if excsnap is not None:
if excsnap.type.__name__ == 'ImportError':
raise ImportError(excsnap.msg)
def run_with_shared_gil(self, script):
interpid = _interpreters.create(isolated=False)
try:
_interpreters.run_string(interpid, script)
except _interpreters.RunFailedError as exc:
if m := self.ERROR.match(str(exc)):
modname, = m.groups()
raise ImportError(modname)
excsnap = _interpreters.run_string(interpid, script)
if excsnap is not None:
if excsnap.type.__name__ == 'ImportError':
raise ImportError(excsnap.msg)
@unittest.skipIf(_testsinglephase is None, "test requires _testsinglephase module")
def test_single_phase_init_module(self):