Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d683f49

Browse filesBrowse files
authored
pythongh-111201: fix auto-indent in pyrepl for muliple pound comments (python#123196)
1 parent 67957ea commit d683f49
Copy full SHA for d683f49

File tree

Expand file treeCollapse file tree

2 files changed

+19
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-1
lines changed

‎Lib/_pyrepl/readline.py

Copy file name to clipboardExpand all lines: Lib/_pyrepl/readline.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def _should_auto_indent(buffer: list[str], pos: int) -> bool:
249249
while pos > 0:
250250
pos -= 1
251251
if last_char is None:
252-
if buffer[pos] not in " \t\n": # ignore whitespaces
252+
if buffer[pos] not in " \t\n#": # ignore whitespaces and comments
253253
last_char = buffer[pos]
254254
else:
255255
# even if we found a non-whitespace character before

‎Lib/test/test_pyrepl/test_pyrepl.py

Copy file name to clipboardExpand all lines: Lib/test/test_pyrepl/test_pyrepl.py
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,24 @@ def test_auto_indent_with_comment(self):
466466
output = multiline_input(reader)
467467
self.assertEqual(output, output_code)
468468

469+
def test_auto_indent_with_multicomment(self):
470+
# fmt: off
471+
events = code_to_events(
472+
"def f(): ## foo\n"
473+
"pass\n\n"
474+
)
475+
476+
output_code = (
477+
"def f(): ## foo\n"
478+
" pass\n"
479+
" "
480+
)
481+
# fmt: on
482+
483+
reader = self.prepare_reader(events)
484+
output = multiline_input(reader)
485+
self.assertEqual(output, output_code)
486+
469487
def test_auto_indent_ignore_comments(self):
470488
# fmt: off
471489
events = code_to_events(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.