Skip to content

Commit a8e35e8

Browse files
gh-119443: Turn off from __future__ import annotations in REPL (#119493)
1 parent 548a11d commit a8e35e8

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
@@ -100,7 +100,7 @@ def runsource(self, source, filename="<input>", symbol="single"):
100100
the_symbol = symbol if stmt is last_stmt else "exec"
101101
item = wrapper([stmt])
102102
try:
103-
code = compile(item, filename, the_symbol)
103+
code = compile(item, filename, the_symbol, dont_inherit=True)
104104
except (OverflowError, ValueError):
105105
self.showsyntaxerror(filename)
106106
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)