[Python-checkins] [3.12] gh-105908: fix `barry_as_FLUFL` future import (GH-105909) (#105930)

JelleZijlstra webhook-mailer at python.org
Mon Jun 19 23:05:23 EDT 2023


https://github.com/python/cpython/commit/cc18a8b78ac85159dad8f2f3ee93799f5df6fa82
commit: cc18a8b78ac85159dad8f2f3ee93799f5df6fa82
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: JelleZijlstra <jelle.zijlstra at gmail.com>
date: 2023-06-20T03:05:20Z
summary:

[3.12] gh-105908: fix `barry_as_FLUFL` future import (GH-105909) (#105930)

(cherry picked from commit 28187a9c4f95affe50fd37e0db0db177e2b9c2e9)

Co-authored-by: Crowthebird <78076854+thatbirdguythatuknownot at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Core and Builtins/2023-06-19-11-04-01.gh-issue-105908.7oanny.rst
M Lib/test/test_future.py
M Python/compile.c

diff --git a/Lib/test/test_future.py b/Lib/test/test_future.py
index b8b591a1bcf2c..4730bfafbd9cf 100644
--- a/Lib/test/test_future.py
+++ b/Lib/test/test_future.py
@@ -4,6 +4,7 @@
 import ast
 import unittest
 from test.support import import_helper
+from test.support.script_helper import spawn_python, kill_python
 from textwrap import dedent
 import os
 import re
@@ -121,6 +122,13 @@ def test_unicode_literals_exec(self):
         exec("from __future__ import unicode_literals; x = ''", {}, scope)
         self.assertIsInstance(scope["x"], str)
 
+    def test_syntactical_future_repl(self):
+        p = spawn_python('-i')
+        p.stdin.write(b"from __future__ import barry_as_FLUFL\n")
+        p.stdin.write(b"2 <> 3\n")
+        out = kill_python(p)
+        self.assertNotIn(b'SyntaxError: invalid syntax', out)
+
 class AnnotationsFutureTestCase(unittest.TestCase):
     template = dedent(
         """
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-06-19-11-04-01.gh-issue-105908.7oanny.rst b/Misc/NEWS.d/next/Core and Builtins/2023-06-19-11-04-01.gh-issue-105908.7oanny.rst
new file mode 100644
index 0000000000000..03db3f064f503
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2023-06-19-11-04-01.gh-issue-105908.7oanny.rst	
@@ -0,0 +1 @@
+Fixed bug where :gh:`99111` breaks future import ``barry_as_FLUFL`` in the Python REPL.
diff --git a/Python/compile.c b/Python/compile.c
index f593e957caae9..a8d0016a10786 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -510,8 +510,10 @@ static PyCodeObject *optimize_and_assemble(struct compiler *, int addNone);
 
 static int
 compiler_setup(struct compiler *c, mod_ty mod, PyObject *filename,
-               PyCompilerFlags flags, int optimize, PyArena *arena)
+               PyCompilerFlags *flags, int optimize, PyArena *arena)
 {
+    PyCompilerFlags local_flags = _PyCompilerFlags_INIT;
+
     c->c_const_cache = PyDict_New();
     if (!c->c_const_cache) {
         return ERROR;
@@ -527,10 +529,13 @@ compiler_setup(struct compiler *c, mod_ty mod, PyObject *filename,
     if (!_PyFuture_FromAST(mod, filename, &c->c_future)) {
         return ERROR;
     }
-    int merged = c->c_future.ff_features | flags.cf_flags;
+    if (!flags) {
+        flags = &local_flags;
+    }
+    int merged = c->c_future.ff_features | flags->cf_flags;
     c->c_future.ff_features = merged;
-    flags.cf_flags = merged;
-    c->c_flags = flags;
+    flags->cf_flags = merged;
+    c->c_flags = *flags;
     c->c_optimize = (optimize == -1) ? _Py_GetConfig()->optimization_level : optimize;
     c->c_nestlevel = 0;
 
@@ -555,12 +560,11 @@ static struct compiler*
 new_compiler(mod_ty mod, PyObject *filename, PyCompilerFlags *pflags,
              int optimize, PyArena *arena)
 {
-    PyCompilerFlags flags = pflags ? *pflags : _PyCompilerFlags_INIT;
     struct compiler *c = PyMem_Calloc(1, sizeof(struct compiler));
     if (c == NULL) {
         return NULL;
     }
-    if (compiler_setup(c, mod, filename, flags, optimize, arena) < 0) {
+    if (compiler_setup(c, mod, filename, pflags, optimize, arena) < 0) {
         compiler_free(c);
         return NULL;
     }



More information about the Python-checkins mailing list