mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	gh-118877: Fix AssertionError crash in pyrepl (#118936)
This commit is contained in:
		
							parent
							
								
									7e1a130b8f
								
							
						
					
					
						commit
						c0d81b2566
					
				
					 2 changed files with 25 additions and 4 deletions
				
			
		|  | @ -34,9 +34,7 @@ | ||||||
| 
 | 
 | ||||||
| # types | # types | ||||||
| if False: | if False: | ||||||
|     from .reader import Reader |  | ||||||
|     from .historical_reader import HistoricalReader |     from .historical_reader import HistoricalReader | ||||||
|     from .console import Event |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Command: | class Command: | ||||||
|  | @ -245,7 +243,7 @@ def do(self) -> None: | ||||||
|             x, y = r.pos2xy() |             x, y = r.pos2xy() | ||||||
|             new_y = y - 1 |             new_y = y - 1 | ||||||
| 
 | 
 | ||||||
|             if new_y < 0: |             if r.bol() == 0: | ||||||
|                 if r.historyi > 0: |                 if r.historyi > 0: | ||||||
|                     r.select_item(r.historyi - 1) |                     r.select_item(r.historyi - 1) | ||||||
|                     return |                     return | ||||||
|  |  | ||||||
|  | @ -607,6 +607,30 @@ def test_global_namespace_completion(self): | ||||||
|         output = multiline_input(reader, namespace) |         output = multiline_input(reader, namespace) | ||||||
|         self.assertEqual(output, "python") |         self.assertEqual(output, "python") | ||||||
| 
 | 
 | ||||||
|  |     def test_updown_arrow_with_completion_menu(self): | ||||||
|  |         """Up arrow in the middle of unfinished tab completion when the menu is displayed | ||||||
|  |         should work and trigger going back in history. Down arrow should subsequently | ||||||
|  |         get us back to the incomplete command.""" | ||||||
|  |         code = "import os\nos.\t\t" | ||||||
|  |         namespace = {"os": os} | ||||||
|  | 
 | ||||||
|  |         events = itertools.chain( | ||||||
|  |             code_to_events(code), | ||||||
|  |             [ | ||||||
|  |                 Event(evt='key', data='up', raw=bytearray(b'\x1bOA')), | ||||||
|  |                 Event(evt="key", data="down", raw=bytearray(b"\x1bOB")), | ||||||
|  |             ], | ||||||
|  |             code_to_events("\n") | ||||||
|  |         ) | ||||||
|  |         reader = self.prepare_reader(events, namespace=namespace) | ||||||
|  |         output = multiline_input(reader, namespace) | ||||||
|  |         # This is the first line, nothing to see here | ||||||
|  |         self.assertEqual(output, "import os") | ||||||
|  |         # This is the second line. We pressed up and down arrows | ||||||
|  |         # so we should end up where we were when we initiated tab completion. | ||||||
|  |         output = multiline_input(reader, namespace) | ||||||
|  |         self.assertEqual(output, "os.") | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| @patch("_pyrepl.curses.tigetstr", lambda x: b"") | @patch("_pyrepl.curses.tigetstr", lambda x: b"") | ||||||
| class TestUnivEventQueue(TestCase): | class TestUnivEventQueue(TestCase): | ||||||
|  | @ -1001,6 +1025,5 @@ def test_up_arrow_after_ctrl_r(self): | ||||||
|         reader, _ = handle_all_events(events) |         reader, _ = handle_all_events(events) | ||||||
|         self.assert_screen_equals(reader, "") |         self.assert_screen_equals(reader, "") | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||||
|     unittest.main() |     unittest.main() | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Daniel Hollas
						Daniel Hollas