]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111201: fix auto-indent in pyrepl for muliple pound comments (#123196)
authorArnon Yaari <wiggin15@yahoo.com>
Fri, 6 Sep 2024 07:33:40 +0000 (10:33 +0300)
committerGitHub <noreply@github.com>
Fri, 6 Sep 2024 07:33:40 +0000 (07:33 +0000)
Lib/_pyrepl/readline.py
Lib/test/test_pyrepl/test_pyrepl.py

index dfacfd84999136362f4f17f021aa4cdf2156d098..a6ef138e8b4ec82bb3da23939b34ebae7b6b806d 100644 (file)
@@ -249,7 +249,7 @@ def _should_auto_indent(buffer: list[str], pos: int) -> bool:
     while pos > 0:
         pos -= 1
         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]
         else:
             # even if we found a non-whitespace character before
index 012ce7c5a6ba19ac65cd8bdc94677ebc471ca430..d9d83c4c07ed79ac4199babeb65e81f9ee46388a 100644 (file)
@@ -466,6 +466,24 @@ class TestPyReplAutoindent(TestCase):
         output = multiline_input(reader)
         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):
         # fmt: off
         events = code_to_events(