gh-133710: Enhance pyrepl auto-indent by tanloong · Pull Request #140710 · python/cpython · GitHub
Skip to content
Open
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
34 changes: 17 additions & 17 deletions Lib/_pyrepl/readline.py
58 changes: 58 additions & 0 deletions Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,27 @@ def test_auto_indent_with_comment(self):
output = multiline_input(reader)
self.assertEqual(output, output_code)

# fmt: off
events = itertools.chain(
code_to_events("def f():\n"),
[
Event(evt="key", data="backspace", raw=b"\x08"),
],
code_to_events("# foo\npass\n\n")
)

output_code = (
"def f():\n"
"# foo\n"
" pass\n"
" "
)
# fmt: on

reader = self.prepare_reader(events)
output = multiline_input(reader)
self.assertEqual(output, output_code)

def test_auto_indent_with_multicomment(self):
# fmt: off
events = code_to_events(
Expand Down Expand Up @@ -627,6 +648,43 @@ def test_auto_indent_ignore_comments(self):
output = multiline_input(reader)
self.assertEqual(output, output_code)

def test_dont_indent_hashtag(self):
# fmt: off
events = code_to_events(
"if ' ' == '#':\n"
"pass\n\n"
)

output_code = (
"if ' ' == '#':\n"
" pass\n"
" "
)
# fmt: on

reader = self.prepare_reader(events)
output = multiline_input(reader)
self.assertEqual(output, output_code)

def test_dont_indent_in_multiline_string(self):
# fmt: off
events = code_to_events(
"s = '''\n"
"Note:\n"
"'''\n\n"
)

output_code = (
"s = '''\n"
"Note:\n"
"'''"
)
# fmt: on

reader = self.prepare_reader(events)
output = multiline_input(reader)
self.assertEqual(output, output_code)


class TestPyReplOutput(ScreenEqualMixin, TestCase):
def prepare_reader(self, events):
Expand Down
Loading