[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 a8e35e8eba)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-05-29 03:26:19 +02:00 committed by GitHub
parent ef9fd10670
commit 17d3398486
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 1 deletions

View 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

View 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")

View file

@ -0,0 +1,2 @@
The interactive REPL no longer runs with ``from __future__ import
annotations`` enabled. Patch by Jelle Zijlstra.