-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
gh-146044: Fix ctrl-w (unix-word-rubout) to use whitespace word boundaries #146174
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
Open
kimimgo
wants to merge
8
commits into
python:main
Choose a base branch
from
kimimgo:fix/pyrepl-ctrl-w-146044
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+56
−1
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
678eefd
Fix ctrl-w (unix-word-rubout) to use whitespace word boundaries (#146…
kimimgo 853cb8c
Fix test: prepare_console() requires events argument
kimimgo 99023b2
Add NEWS entry for gh-146044
kimimgo e6d27d9
Address review: rename bow_ws, move tests to TestReader, add tab support
kimimgo 9f54090
Fix trailing blank lines in test_reader.py
kimimgo 140faf1
Address review: close docstring on separate line
kimimgo c8d1759
Address review: remove issue URL from docstring, add newline test
kimimgo 0a25f0b
Address review: use index() instead of magic number for pos
kimimgo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -358,6 +358,41 @@ def test_setpos_from_xy_for_non_printing_char(self): | |||||||||
| reader.setpos_from_xy(8, 0) | ||||||||||
| self.assertEqual(reader.pos, 7) | ||||||||||
|
|
||||||||||
| def test_bow_ws_stops_at_whitespace(self): | ||||||||||
| # See https://github.com/python/cpython/issues/146044. | ||||||||||
| reader = prepare_reader(prepare_console([])) | ||||||||||
| reader.buffer = list("foo.bar baz") | ||||||||||
| reader.pos = len(reader.buffer) | ||||||||||
| self.assertEqual(reader.bow_ws(), 8) | ||||||||||
|
|
||||||||||
| def test_bow_ws_includes_punctuation_in_word(self): | ||||||||||
| reader = prepare_reader(prepare_console([])) | ||||||||||
| buf = "foo.bar(baz) qux" | ||||||||||
| reader.buffer = list(buf) | ||||||||||
| reader.pos = buf.index(")") + 1 | ||||||||||
| self.assertEqual(reader.bow_ws(), 0) | ||||||||||
|
|
||||||||||
| def test_bow_vs_bow_ws(self): | ||||||||||
| reader = prepare_reader(prepare_console([])) | ||||||||||
| reader.buffer = list("foo.bar") | ||||||||||
| reader.pos = len(reader.buffer) | ||||||||||
| # bow() stops at '.' so we return the index of 'b' in "bar" | ||||||||||
| self.assertEqual(reader.bow(), 4) | ||||||||||
| # bow_ws() treats entire "foo.bar" as one word | ||||||||||
| self.assertEqual(reader.bow_ws(), 0) | ||||||||||
|
|
||||||||||
| def test_bow_ws_with_tabs(self): | ||||||||||
| reader = prepare_reader(prepare_console([])) | ||||||||||
| reader.buffer = list("foo\tbar") | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests with \n and ensure that you also properly jump lines. |
||||||||||
| reader.pos = len(reader.buffer) | ||||||||||
| self.assertEqual(reader.bow_ws(), 4) | ||||||||||
|
|
||||||||||
|
Comment on lines
+388
to
+389
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| def test_bow_ws_with_newlines(self): | ||||||||||
| reader = prepare_reader(prepare_console([])) | ||||||||||
| reader.buffer = list("foo\nbar") | ||||||||||
| reader.pos = len(reader.buffer) | ||||||||||
| self.assertEqual(reader.bow_ws(), 4) | ||||||||||
|
|
||||||||||
| @force_colorized_test_class | ||||||||||
| class TestReaderInColor(ScreenEqualMixin, TestCase): | ||||||||||
| def test_syntax_highlighting_basic(self): | ||||||||||
|
|
||||||||||
3 changes: 3 additions & 0 deletions
3
Misc/NEWS.d/next/Library/2026-03-20-00-00-01.gh-issue-146044.WsCtrl.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Fix ``unix-word-rubout`` (Ctrl-W) in the REPL to use whitespace-only word | ||
| boundaries, matching behavior of the basic REPL. Previously it used | ||
| syntax-table boundaries which treated punctuation as word separators. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are the existing tests for bow()? id there are some, please put those tests next to them