summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2020-06-20 16:57:11 +0200
committerStefan Behnel <stefan_ml@behnel.de>2020-06-20 16:57:11 +0200
commite87fb0ab2b5bc830d738ab96e2ea159ae3d28372 (patch)
treeee234190fbf80f8c11f942e9d1ec55c26d3b4aea
parenta7a3dafc6fbc018029cf779fa5bfd163f402a3e0 (diff)
downloadcython-e87fb0ab2b5bc830d738ab96e2ea159ae3d28372.tar.gz
exec() did not allow recent Python syntax features in Py3.8+ due to https://bugs.python.org/issue35975
Closes https://github.com/cython/cython/issues/3695
-rw-r--r--CHANGES.rst4
-rw-r--r--Cython/Utility/Builtins.c3
-rw-r--r--tests/run/exectest.pyx15
3 files changed, 22 insertions, 0 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 1f4b6d5f2..46ad403e4 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -11,6 +11,10 @@ Bugs fixed
* Fix a regression in 0.29.20 where ``__div__`` failed to be found in extension types.
(Github issue #3688)
+* ``exec()`` did not allow recent Python syntax features in Py3.8+ due to
+ https://bugs.python.org/issue35975.
+ (Github issue #3695)
+
* Binding staticmethods of Cython functions were not behaving like Python methods in Py3.
Patch by Jeroen Demeyer and Michał Górny. (Github issue #3106)
diff --git a/Cython/Utility/Builtins.c b/Cython/Utility/Builtins.c
index 3c0e49129..eaf93c0a3 100644
--- a/Cython/Utility/Builtins.c
+++ b/Cython/Utility/Builtins.c
@@ -128,6 +128,9 @@ static PyObject* __Pyx_PyExec3(PyObject* o, PyObject* globals, PyObject* locals)
} else {
PyCompilerFlags cf;
cf.cf_flags = 0;
+#if PY_VERSION_HEX >= 0x030800A3
+ cf.cf_feature_version = PY_MINOR_VERSION;
+#endif
if (PyUnicode_Check(o)) {
cf.cf_flags = PyCF_SOURCE_IS_UTF8;
s = PyUnicode_AsUTF8String(o);
diff --git a/tests/run/exectest.pyx b/tests/run/exectest.pyx
index ec659511d..6b5f849ab 100644
--- a/tests/run/exectest.pyx
+++ b/tests/run/exectest.pyx
@@ -145,3 +145,18 @@ def exec_invalid_type(x):
TypeError: exec: arg 1 must be string, bytes or code object, got int
"""
exec x in {}
+
+
+def exec_with_new_features(s, d):
+ """
+ >>> import sys
+ >>> pyversion = sys.version_info[:2]
+
+ >>> d = {}
+ >>> exec_with_new_features('print(123)', d)
+ 123
+ >>> if pyversion == (2, 7): exec_with_new_features('exec "123"', d)
+ >>> if pyversion >= (3, 6): exec_with_new_features('f = f"abc"', d)
+ >>> if pyversion >= (3, 8): exec_with_new_features('a = (b := 1)', d)
+ """
+ exec s in d