diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2025-05-25 23:33:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-25 23:33:02 (GMT) |
commit | 7216f7b59c30313fa27a30765fc7340df2f5ccef (patch) | |
tree | 902882307ed300e3ddab178a18fa3faeaa437694 /Lib/test/test_pyrepl/test_pyrepl.py | |
parent | 1822f33b1af989ebb9e7a5b58bd40721fca9a218 (diff) | |
download | cpython-7216f7b59c30313fa27a30765fc7340df2f5ccef.zip cpython-7216f7b59c30313fa27a30765fc7340df2f5ccef.tar.gz cpython-7216f7b59c30313fa27a30765fc7340df2f5ccef.tar.bz2 |
[3.14] gh-69605: Disable PyREPL module autocomplete fallback on regular completion (gh-134181) (gh-134680)
(cherry picked from commit 0e3bc962c6462f836751e35ef35fa837fd952550)
Co-authored-by: Loïc Simon <loic.simon@napta.io>
Diffstat (limited to 'Lib/test/test_pyrepl/test_pyrepl.py')
-rw-r--r-- | Lib/test/test_pyrepl/test_pyrepl.py | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py index abb4bd1..aa3a592 100644 --- a/Lib/test/test_pyrepl/test_pyrepl.py +++ b/Lib/test/test_pyrepl/test_pyrepl.py @@ -918,7 +918,14 @@ class TestPyReplCompleter(TestCase): class TestPyReplModuleCompleter(TestCase): def setUp(self): + import importlib + # Make iter_modules() search only the standard library. + # This makes the test more reliable in case there are + # other user packages/scripts on PYTHONPATH which can + # interfere with the completions. + lib_path = os.path.dirname(importlib.__path__[0]) self._saved_sys_path = sys.path + sys.path = [lib_path] def tearDown(self): sys.path = self._saved_sys_path @@ -932,14 +939,6 @@ class TestPyReplModuleCompleter(TestCase): return reader def test_import_completions(self): - import importlib - # Make iter_modules() search only the standard library. - # This makes the test more reliable in case there are - # other user packages/scripts on PYTHONPATH which can - # intefere with the completions. - lib_path = os.path.dirname(importlib.__path__[0]) - sys.path = [lib_path] - cases = ( ("import path\t\n", "import pathlib"), ("import importlib.\t\tres\t\n", "import importlib.resources"), @@ -1052,6 +1051,19 @@ class TestPyReplModuleCompleter(TestCase): output = reader.readline() self.assertEqual(output, expected) + def test_no_fallback_on_regular_completion(self): + cases = ( + ("import pri\t\n", "import pri"), + ("from pri\t\n", "from pri"), + ("from typing import Na\t\n", "from typing import Na"), + ) + for code, expected in cases: + with self.subTest(code=code): + events = code_to_events(code) + reader = self.prepare_reader(events, namespace={}) + output = reader.readline() + self.assertEqual(output, expected) + def test_get_path_and_prefix(self): cases = ( ('', ('', '')), |