Skip to content

gh-122237: Fix REPL wrong auto-indentation with comments #122238

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

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 11 additions & 2 deletions 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
last_char = buffer[pos]
else:
# even if we found a non-whitespace character before
Expand All @@ -258,7 +258,16 @@ def _should_auto_indent(buffer: list[str], pos: int) -> bool:
if buffer[pos] == "\n":
break
if buffer[pos] == "#":
last_char = None
while pos:
pos -= 1
char = buffer[pos]
if char == "\n":
return False
elif char not in " \t#":
last_char = char
break
else:
return False
return last_char == ":"


Expand Down
Loading