mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	gh-111201: fix auto-indent in pyrepl for muliple pound comments (#123196)
This commit is contained in:
		
							parent
							
								
									67957ea77d
								
							
						
					
					
						commit
						d683f49a7b
					
				
					 2 changed files with 19 additions and 1 deletions
				
			
		|  | @ -249,7 +249,7 @@ def _should_auto_indent(buffer: list[str], pos: int) -> bool: | ||||||
|     while pos > 0: |     while pos > 0: | ||||||
|         pos -= 1 |         pos -= 1 | ||||||
|         if last_char is None: |         if last_char is None: | ||||||
|             if buffer[pos] not in " \t\n":  # ignore whitespaces |             if buffer[pos] not in " \t\n#":  # ignore whitespaces and comments | ||||||
|                 last_char = buffer[pos] |                 last_char = buffer[pos] | ||||||
|         else: |         else: | ||||||
|             # even if we found a non-whitespace character before |             # even if we found a non-whitespace character before | ||||||
|  |  | ||||||
|  | @ -466,6 +466,24 @@ def test_auto_indent_with_comment(self): | ||||||
|         output = multiline_input(reader) |         output = multiline_input(reader) | ||||||
|         self.assertEqual(output, output_code) |         self.assertEqual(output, output_code) | ||||||
| 
 | 
 | ||||||
|  |     def test_auto_indent_with_multicomment(self): | ||||||
|  |         # fmt: off | ||||||
|  |         events = code_to_events( | ||||||
|  |             "def f():  ## foo\n" | ||||||
|  |                 "pass\n\n" | ||||||
|  |         ) | ||||||
|  | 
 | ||||||
|  |         output_code = ( | ||||||
|  |             "def f():  ## foo\n" | ||||||
|  |             "    pass\n" | ||||||
|  |             "    " | ||||||
|  |         ) | ||||||
|  |         # fmt: on | ||||||
|  | 
 | ||||||
|  |         reader = self.prepare_reader(events) | ||||||
|  |         output = multiline_input(reader) | ||||||
|  |         self.assertEqual(output, output_code) | ||||||
|  | 
 | ||||||
|     def test_auto_indent_ignore_comments(self): |     def test_auto_indent_ignore_comments(self): | ||||||
|         # fmt: off |         # fmt: off | ||||||
|         events = code_to_events( |         events = code_to_events( | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Arnon Yaari
						Arnon Yaari