diff options
| author | Guido van Rossum <guido@python.org> | 2020-06-21 10:14:44 -0700 |
|---|---|---|
| committer | Guido van Rossum <guido@python.org> | 2020-06-21 10:15:47 -0700 |
| commit | 274e5e01f95857015cd9c9b9e535d57b5e3dae91 (patch) | |
| tree | 885eba78161d805a3503e6277cf877ea48a7f9ed | |
| parent | f5d9931744502c111c8e3b2204d573a5de00e043 (diff) | |
| download | cpython-git-274e5e01f95857015cd9c9b9e535d57b5e3dae91.tar.gz | |
Add test by Stefan Behnel
| -rw-r--r-- | Lib/test/test_capi.py | 21 | ||||
| -rw-r--r-- | Modules/_testcapimodule.c | 4 |
2 files changed, 24 insertions, 1 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index a9e051dbb3..4efecfdb15 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -626,6 +626,27 @@ class SubinterpreterTest(unittest.TestCase): self.assertNotEqual(pickle.load(f), id(sys.modules)) self.assertNotEqual(pickle.load(f), id(builtins)) + def test_subinterps_recent_language_features(self): + r, w = os.pipe() + code = """if 1: + import pickle + with open({:d}, "wb") as f: + + @(lambda x:x) # Py 3.9 + def noop(x): return x + + a = (b := f'1{{2}}3') + noop('x') # Py 3.8 (:=) / 3.6 (f'') + + async def foo(arg): return await arg # Py 3.5 + + pickle.dump(dict(a=a, b=b), f) + """.format(w) + + with open(r, "rb") as f: + ret = support.run_in_subinterp(code) + self.assertEqual(ret, 0) + self.assertEqual(pickle.load(f), {'a': '123x', 'b': '123'}) + def test_mutate_exception(self): """ Exceptions saved in global module state get shared between diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 5302641a9a..22606fbba1 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -3468,6 +3468,8 @@ run_in_subinterp(PyObject *self, PyObject *args) const char *code; int r; PyThreadState *substate, *mainstate; + /* only initialise 'cflags.cf_flags' to test backwards compatibility */ + PyCompilerFlags cflags = {0}; if (!PyArg_ParseTuple(args, "s:run_in_subinterp", &code)) @@ -3486,7 +3488,7 @@ run_in_subinterp(PyObject *self, PyObject *args) PyErr_SetString(PyExc_RuntimeError, "sub-interpreter creation failed"); return NULL; } - r = PyRun_SimpleString(code); + r = PyRun_SimpleStringFlags(code, &cflags); Py_EndInterpreter(substate); PyThreadState_Swap(mainstate); |
