Skip to content

Commit 17d3398

Browse files
[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 a8e35e8) Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent ef9fd10 commit 17d3398

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Lib/_pyrepl/simple_interact.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def runsource(self, source, filename="<input>", symbol="single"):
9595
the_symbol = symbol if stmt is last_stmt else "exec"
9696
item = wrapper([stmt])
9797
try:
98-
code = compile(item, filename, the_symbol)
98+
code = compile(item, filename, the_symbol, dont_inherit=True)
9999
except (OverflowError, ValueError):
100100
self.showsyntaxerror(filename)
101101
return False

Lib/test/test_pyrepl/test_interact.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,12 @@ def test_runsource_shows_syntax_error_for_failed_compilation(self):
9494
with patch.object(console, "showsyntaxerror") as mock_showsyntaxerror:
9595
console.runsource(source)
9696
mock_showsyntaxerror.assert_called_once()
97+
98+
def test_no_active_future(self):
99+
console = InteractiveColoredConsole()
100+
source = "x: int = 1; print(__annotations__)"
101+
f = io.StringIO()
102+
with contextlib.redirect_stdout(f):
103+
result = console.runsource(source)
104+
self.assertFalse(result)
105+
self.assertEqual(f.getvalue(), "{'x': <class 'int'>}\n")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The interactive REPL no longer runs with ``from __future__ import
2+
annotations`` enabled. Patch by Jelle Zijlstra.

0 commit comments

Comments
 (0)