Skip to content

Commit

Permalink
pythongh-119443: Turn off from __future__ import annotations in REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed May 24, 2024
1 parent b48a3db commit 91d2d8c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/_pyrepl/simple_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def runsource(self, source, filename="<input>", symbol="single"):
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
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_pyrepl/test_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,12 @@ def test_runsource_shows_syntax_error_for_failed_compilation(self):
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")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The interactive REPL no longer runs with ``from __future__ import
annotations`` enabled. Patch by Jelle Zijlstra.

0 comments on commit 91d2d8c

Please sign in to comment.