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:20:24 -0700
commit1311ec742103b002fa45df974086da3110afc6e3 (patch)
treec2312a386d7fd5286e7149d432cabd737ba12bc2
parent2235257bf3dd7640ef4e5ccea16ed8f70a80052b (diff)
downloadcpython-git-1311ec742103b002fa45df974086da3110afc6e3.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 584c104645..1028587a20 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -584,6 +584,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 da3579c2cc..f74756163f 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -3345,6 +3345,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))
@@ -3363,7 +3365,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);