mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	gh-119443: Turn off from __future__ import annotations in REPL (#119493)
This commit is contained in:
		
							parent
							
								
									548a11d5cf
								
							
						
					
					
						commit
						a8e35e8eba
					
				
					 3 changed files with 12 additions and 1 deletions
				
			
		|  | @ -100,7 +100,7 @@ def runsource(self, source, filename="<input>", symbol="single"): | ||||||
|             the_symbol = symbol if stmt is last_stmt else "exec" |             the_symbol = symbol if stmt is last_stmt else "exec" | ||||||
|             item = wrapper([stmt]) |             item = wrapper([stmt]) | ||||||
|             try: |             try: | ||||||
|                 code = compile(item, filename, the_symbol) |                 code = compile(item, filename, the_symbol, dont_inherit=True) | ||||||
|             except (OverflowError, ValueError): |             except (OverflowError, ValueError): | ||||||
|                     self.showsyntaxerror(filename) |                     self.showsyntaxerror(filename) | ||||||
|                     return False |                     return False | ||||||
|  |  | ||||||
|  | @ -94,3 +94,12 @@ def test_runsource_shows_syntax_error_for_failed_compilation(self): | ||||||
|         with patch.object(console, "showsyntaxerror") as mock_showsyntaxerror: |         with patch.object(console, "showsyntaxerror") as mock_showsyntaxerror: | ||||||
|             console.runsource(source) |             console.runsource(source) | ||||||
|             mock_showsyntaxerror.assert_called_once() |             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") | ||||||
|  |  | ||||||
|  | @ -0,0 +1,2 @@ | ||||||
|  | The interactive REPL no longer runs with ``from __future__ import | ||||||
|  | annotations`` enabled. Patch by Jelle Zijlstra. | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jelle Zijlstra
						Jelle Zijlstra