Skip to content

gh-111201: fix auto-indent in pyrepl for muliple pound comments #123196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading