8000 gh-118911: Trailing whitespace in a block shouldn't prevent the user from terminating the code block by aelsayed95 · Pull Request #119355 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-118911: Trailing whitespace in a block shouldn't prevent the user from terminating the code block #119355

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 8 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
for clarity
  • Loading branch information
aelsayed95 committed May 21, 2024
commit 4996c5ea3be47dd062548fa07f5c46639cd1ffab
4 changes: 2 additions & 2 deletions Lib/_pyrepl/readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def do(self) -> None:
if "\n" in r.buffer[r.pos :] or (
r.more_lines is not None and r.more_lines(text)
):
def _whitespace_before_pos():
def _newline_before_pos():
before_idx = r.pos - 1
while before_idx > 0 and text[before_idx].isspace():
before_idx -= 1
Expand All @@ -232,7 +232,7 @@ def _whitespace_before_pos():
# if there's already a new line before the cursor then
# even if the cursor is followed by whitespace, we assume
# the user is trying to terminate the block
if _whitespace_before_pos() and text[r.pos:].isspace():
if _newline_before_pos() and text[r.pos:].isspace():
self.finish = True
else:
#
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_pyrepl/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,4 @@ def test_newline_within_block_trailing_whitespace(self):
" " # HistoricalReader will trim trailing whitespace
)
self.assert_screen_equals(reader, expected)
self.assertEqual(reader.finished, True)
self.assertTrue(reader.finished)
0