Skip to content

Commit

Permalink
pythongh-111201: fix auto-indent in pyrepl for muliple pound comments (
Browse files Browse the repository at this point in the history
  • Loading branch information
wiggin15 authored Sep 6, 2024
1 parent 67957ea commit d683f49
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/_pyrepl/readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d683f49

Please sign in to comment.