https://github.com/python/cpython/commit/b221c5bba16d1406abbef13eba30b944bbcc92e1
commit: b221c5bba16d1406abbef13eba30b944bbcc92e1
branch: 3.13
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: ambv <luk...@langa.pl>
date: 2024-09-06T13:09:22+02:00
summary:

[3.13] gh-111201: fix auto-indent in pyrepl for muliple pound comments 
(GH-123196) (GH-123764)

(cherry picked from commit d683f49a7b0635a26150cfbb398a3d93b227a74e)

Co-authored-by: Arnon Yaari <wiggi...@yahoo.com>

files:
M Lib/_pyrepl/readline.py
M Lib/test/test_pyrepl/test_pyrepl.py

diff --git a/Lib/_pyrepl/readline.py b/Lib/_pyrepl/readline.py
index dfacfd84999136..a6ef138e8b4ec8 100644
--- a/Lib/_pyrepl/readline.py
+++ b/Lib/_pyrepl/readline.py
@@ -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
diff --git a/Lib/test/test_pyrepl/test_pyrepl.py 
b/Lib/test/test_pyrepl/test_pyrepl.py
index 012ce7c5a6ba19..d9d83c4c07ed79 100644
--- a/Lib/test/test_pyrepl/test_pyrepl.py
+++ b/Lib/test/test_pyrepl/test_pyrepl.py
@@ -466,6 +466,24 @@ def test_auto_indent_with_comment(self):
         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(

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to