]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-119443: Turn off from __future__ import annotations in REPL (GH-119493...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 29 May 2024 01:26:19 +0000 (03:26 +0200)
committerGitHub <noreply@github.com>
Wed, 29 May 2024 01:26:19 +0000 (01:26 +0000)
gh-119443: Turn off from __future__ import annotations in REPL (GH-119493)
(cherry picked from commit a8e35e8ebad8c3bb44d14968aa05d1acbc028247)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Lib/_pyrepl/simple_interact.py
Lib/test/test_pyrepl/test_interact.py
Misc/NEWS.d/next/Library/2024-05-23-22-29-59.gh-issue-119443.KAGz6S.rst [new file with mode: 0644]

index 8ab4dab757685ee6e85aa265eb1da422b17b797d..3dfb1d7ad736e3e29cab83cb6a9ebf8b8a254974 100644 (file)
@@ -95,7 +95,7 @@ class InteractiveColoredConsole(code.InteractiveConsole):
             the_symbol = symbol if stmt is last_stmt else "exec"
             item = wrapper([stmt])
             try:
-                code = compile(item, filename, the_symbol)
+                code = compile(item, filename, the_symbol, dont_inherit=True)
             except (OverflowError, ValueError):
                     self.showsyntaxerror(filename)
                     return False
index 10e34045bcf92df4ec4ae36b33d697c904e7ebda..6ebd51fe14dd62247d841812822237ab15816366 100644 (file)
@@ -94,3 +94,12 @@ class TestSimpleInteract(unittest.TestCase):
         with patch.object(console, "showsyntaxerror") as mock_showsyntaxerror:
             console.runsource(source)
             mock_showsyntaxerror.assert_called_once()
+
+    def test_no_active_future(self):
+        console = InteractiveColoredConsole()
+        source = "x: int = 1; print(__annotations__)"
+        f = io.StringIO()
+        with contextlib.redirect_stdout(f):
+            result = console.runsource(source)
+        self.assertFalse(result)
+        self.assertEqual(f.getvalue(), "{'x': <class 'int'>}\n")
diff --git a/Misc/NEWS.d/next/Library/2024-05-23-22-29-59.gh-issue-119443.KAGz6S.rst b/Misc/NEWS.d/next/Library/2024-05-23-22-29-59.gh-issue-119443.KAGz6S.rst
new file mode 100644 (file)
index 0000000..4470c56
--- /dev/null
@@ -0,0 +1,2 @@
+The interactive REPL no longer runs with ``from __future__ import
+annotations`` enabled. Patch by Jelle Zijlstra.