summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-05-29 01:26:19 (GMT)
committerGitHub <noreply@github.com>2024-05-29 01:26:19 (GMT)
commit17d3398486dcbc6f5e977bf4c052d7780013c074 (patch)
treec8eae2e903be8bb1f71e034666756cc87567b159
parentef9fd10670f70c3c26bd1f9eba48cf26229f9052 (diff)
downloadcpython-17d3398486dcbc6f5e977bf4c052d7780013c074.zip
cpython-17d3398486dcbc6f5e977bf4c052d7780013c074.tar.gz
cpython-17d3398486dcbc6f5e977bf4c052d7780013c074.tar.bz2
[3.13] gh-119443: Turn off from __future__ import annotations in REPL (GH-119493) (#119697)
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>
-rw-r--r--Lib/_pyrepl/simple_interact.py2
-rw-r--r--Lib/test/test_pyrepl/test_interact.py9
-rw-r--r--Misc/NEWS.d/next/Library/2024-05-23-22-29-59.gh-issue-119443.KAGz6S.rst2
3 files changed, 12 insertions, 1 deletions
diff --git a/Lib/_pyrepl/simple_interact.py b/Lib/_pyrepl/simple_interact.py
index 8ab4dab..3dfb1d7 100644
--- a/Lib/_pyrepl/simple_interact.py
+++ b/Lib/_pyrepl/simple_interact.py
@@ -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
diff --git a/Lib/test/test_pyrepl/test_interact.py b/Lib/test/test_pyrepl/test_interact.py
index 10e3404..6ebd51f 100644
--- a/Lib/test/test_pyrepl/test_interact.py
+++ b/Lib/test/test_pyrepl/test_interact.py
@@ -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
index 0000000..4470c56
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-05-23-22-29-59.gh-issue-119443.KAGz6S.rst
@@ -0,0 +1,2 @@
+The interactive REPL no longer runs with ``from __future__ import
+annotations`` enabled. Patch by Jelle Zijlstra.