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 506b1a3

Browse filesBrowse files
koxudaxiambv
andauthored
gh-119205: Fix autocompletion bug in new repl (#119229)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
1 parent a3e4fec commit 506b1a3
Copy full SHA for 506b1a3

File tree

3 files changed

+28
-8
lines changed
Filter options

3 files changed

+28
-8
lines changed

‎Lib/_pyrepl/readline.py

Copy file name to clipboardExpand all lines: Lib/_pyrepl/readline.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
from __future__ import annotations
3030

31+
import warnings
3132
from dataclasses import dataclass, field
3233

3334
import os
@@ -301,7 +302,8 @@ def multiline_input(self, more_lines: MoreLinesCallable, ps1: str, ps2: str) ->
301302
reader.more_lines = more_lines
302303
reader.ps1 = reader.ps2 = ps1
303304
reader.ps3 = reader.ps4 = ps2
304-
return reader.readline(), reader.was_paste_mode_activated
305+
with warnings.catch_warnings(action="ignore"):
306+
return reader.readline(), reader.was_paste_mode_activated
305307
finally:
306308
reader.more_lines = saved
307309
reader.paste_mode = False

‎Lib/test/test_pyrepl/test_pyrepl.py

Copy file name to clipboardExpand all lines: Lib/test/test_pyrepl/test_pyrepl.py
+24-6Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import itertools
2+
import io
23
import os
34
import rlcompleter
4-
import unittest
55
from unittest import TestCase
6+
from unittest.mock import patch
67

7-
from .support import FakeConsole, handle_all_events, handle_events_narrow_console, multiline_input, code_to_events
8+
from .support import FakeConsole, handle_all_events, handle_events_narrow_console
9+
from .support import more_lines, multiline_input, code_to_events
810
from _pyrepl.console import Event
911
from _pyrepl.readline import ReadlineAlikeReader, ReadlineConfig
12+
from _pyrepl.readline import multiline_input as readline_multiline_input
1013

1114

1215
class TestCursorPosition(TestCase):
@@ -475,6 +478,25 @@ def test_updown_arrow_with_completion_menu(self):
475478
output = multiline_input(reader, namespace)
476479
self.assertEqual(output, "os.")
477480

481+
@patch("_pyrepl.readline._ReadlineWrapper.get_reader")
482+
@patch("sys.stderr", new_callable=io.StringIO)
483+
def test_completion_with_warnings(self, mock_stderr, mock_get_reader):
484+
class Dummy:
485+
@property
486+
def test_func(self):
487+
import warnings
488+
warnings.warn("warnings\n")
489+
return None
490+
491+
dummy = Dummy()
492+
events = code_to_events("dummy.test_func.\t\n\n")
493+
namespace = {"dummy": dummy}
494+
reader = self.prepare_reader(events, namespace)
495+
mock_get_reader.return_value = reader
496+
output = readline_multiline_input(more_lines, ">>>", "...")
497+
self.assertEqual(output[0], "dummy.test_func.__")
498+
self.assertEqual(mock_stderr.getvalue(), "")
499+
478500

479501
class TestPasteEvent(TestCase):
480502
def prepare_reader(self, events):
@@ -633,7 +655,3 @@ def test_bracketed_paste_single_line(self):
633655
reader = self.prepare_reader(events)
634656
output = multiline_input(reader)
635657
self.assertEqual(output, input_code)
636-
637-
638-
if __name__ == "__main__":
639-
unittest.main()

‎Lib/test/test_pyrepl/test_unix_eventqueue.py

Copy file name to clipboardExpand all lines: Lib/test/test_pyrepl/test_unix_eventqueue.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
@patch("_pyrepl.curses.tigetstr", lambda x: b"")
10-
class TestUnivEventQueue(unittest.TestCase):
10+
class TestUnixEventQueue(unittest.TestCase):
1111
def setUp(self):
1212
self.file = tempfile.TemporaryFile()
1313

0 commit comments

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