summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2020-06-21 10:14:44 -0700
committerGuido van Rossum <guido@python.org>2020-06-21 10:14:49 -0700
commitfae21b35e718760cb0628201ae3ad0069f7f19af (patch)
tree8113b613d4d8a2fdf679845316745ce171ac8b70
parente9a3faa66f8061e79eaba44f2056e33123e34f16 (diff)
downloadcpython-git-fae21b35e718760cb0628201ae3ad0069f7f19af.tar.gz
Add test by Stefan Behnel
-rw-r--r--Lib/test/test_capi.py21
-rw-r--r--Modules/_testcapimodule.c4
2 files changed, 24 insertions, 1 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index 73e167a0b0..fa5ca1c97f 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -627,6 +627,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 808483ebd7..468e25ff9e 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);