mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	[3.13] gh-119205: Fix autocompletion bug in new repl (GH-119229) (#119407)
(cherry picked from commit 506b1a3ff6)
Co-authored-by: Koudai Aono <koxudaxi@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
			
			
This commit is contained in:
		
							parent
							
								
									aefe2e626e
								
							
						
					
					
						commit
						eafd633fac
					
				
					 3 changed files with 28 additions and 8 deletions
				
			
		|  | @ -28,6 +28,7 @@ | ||||||
| 
 | 
 | ||||||
| from __future__ import annotations | from __future__ import annotations | ||||||
| 
 | 
 | ||||||
|  | import warnings | ||||||
| from dataclasses import dataclass, field | from dataclasses import dataclass, field | ||||||
| 
 | 
 | ||||||
| import os | import os | ||||||
|  | @ -298,7 +299,8 @@ def multiline_input(self, more_lines, ps1, ps2): | ||||||
|             reader.more_lines = more_lines |             reader.more_lines = more_lines | ||||||
|             reader.ps1 = reader.ps2 = ps1 |             reader.ps1 = reader.ps2 = ps1 | ||||||
|             reader.ps3 = reader.ps4 = ps2 |             reader.ps3 = reader.ps4 = ps2 | ||||||
|             return reader.readline(), reader.was_paste_mode_activated |             with warnings.catch_warnings(action="ignore"): | ||||||
|  |                 return reader.readline(), reader.was_paste_mode_activated | ||||||
|         finally: |         finally: | ||||||
|             reader.more_lines = saved |             reader.more_lines = saved | ||||||
|             reader.paste_mode = False |             reader.paste_mode = False | ||||||
|  |  | ||||||
|  | @ -1,12 +1,15 @@ | ||||||
| import itertools | import itertools | ||||||
|  | import io | ||||||
| import os | import os | ||||||
| import rlcompleter | import rlcompleter | ||||||
| import unittest |  | ||||||
| from unittest import TestCase | from unittest import TestCase | ||||||
|  | from unittest.mock import patch | ||||||
| 
 | 
 | ||||||
| from .support import FakeConsole, handle_all_events, handle_events_narrow_console, multiline_input, code_to_events | from .support import FakeConsole, handle_all_events, handle_events_narrow_console | ||||||
|  | from .support import more_lines, multiline_input, code_to_events | ||||||
| from _pyrepl.console import Event | from _pyrepl.console import Event | ||||||
| from _pyrepl.readline import ReadlineAlikeReader, ReadlineConfig | from _pyrepl.readline import ReadlineAlikeReader, ReadlineConfig | ||||||
|  | from _pyrepl.readline import multiline_input as readline_multiline_input | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class TestCursorPosition(TestCase): | class TestCursorPosition(TestCase): | ||||||
|  | @ -475,6 +478,25 @@ def test_updown_arrow_with_completion_menu(self): | ||||||
|         output = multiline_input(reader, namespace) |         output = multiline_input(reader, namespace) | ||||||
|         self.assertEqual(output, "os.") |         self.assertEqual(output, "os.") | ||||||
| 
 | 
 | ||||||
|  |     @patch("_pyrepl.readline._ReadlineWrapper.get_reader") | ||||||
|  |     @patch("sys.stderr", new_callable=io.StringIO) | ||||||
|  |     def test_completion_with_warnings(self, mock_stderr, mock_get_reader): | ||||||
|  |         class Dummy: | ||||||
|  |             @property | ||||||
|  |             def test_func(self): | ||||||
|  |                 import warnings | ||||||
|  |                 warnings.warn("warnings\n") | ||||||
|  |                 return None | ||||||
|  | 
 | ||||||
|  |         dummy = Dummy() | ||||||
|  |         events = code_to_events("dummy.test_func.\t\n\n") | ||||||
|  |         namespace = {"dummy": dummy} | ||||||
|  |         reader = self.prepare_reader(events, namespace) | ||||||
|  |         mock_get_reader.return_value = reader | ||||||
|  |         output = readline_multiline_input(more_lines, ">>>", "...") | ||||||
|  |         self.assertEqual(output[0], "dummy.test_func.__") | ||||||
|  |         self.assertEqual(mock_stderr.getvalue(), "") | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| class TestPasteEvent(TestCase): | class TestPasteEvent(TestCase): | ||||||
|     def prepare_reader(self, events): |     def prepare_reader(self, events): | ||||||
|  | @ -633,7 +655,3 @@ def test_bracketed_paste_single_line(self): | ||||||
|         reader = self.prepare_reader(events) |         reader = self.prepare_reader(events) | ||||||
|         output = multiline_input(reader) |         output = multiline_input(reader) | ||||||
|         self.assertEqual(output, input_code) |         self.assertEqual(output, input_code) | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| if __name__ == "__main__": |  | ||||||
|     unittest.main() |  | ||||||
|  |  | ||||||
|  | @ -7,7 +7,7 @@ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @patch("_pyrepl.curses.tigetstr", lambda x: b"") | @patch("_pyrepl.curses.tigetstr", lambda x: b"") | ||||||
| class TestUnivEventQueue(unittest.TestCase): | class TestUnixEventQueue(unittest.TestCase): | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.file = tempfile.TemporaryFile() |         self.file = tempfile.TemporaryFile() | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Miss Islington (bot)
						Miss Islington (bot)