@@ -929,7 +929,7 @@ def prepare_reader(self, events, namespace):
929
929
reader = ReadlineAlikeReader (console = console , config = config )
930
930
return reader
931
931
932
- def test_import_completions (self ):
932
+ def _only_stdlib_imports (self ):
933
933
import importlib
934
934
# Make iter_modules() search only the standard library.
935
935
# This makes the test more reliable in case there are
@@ -938,22 +938,21 @@ def test_import_completions(self):
938
938
lib_path = os .path .dirname (importlib .__path__ [0 ])
939
939
sys .path = [lib_path ]
940
940
941
+ def test_import_completions (self ):
942
+ self ._only_stdlib_imports ()
941
943
cases = (
942
944
("import path\t \n " , "import pathlib" ),
943
945
("import importlib.\t \t res\t \n " , "import importlib.resources" ),
944
946
("import importlib.resources.\t \t a\t \n " , "import importlib.resources.abc" ),
945
947
("import foo, impo\t \n " , "import foo, importlib" ),
946
948
("import foo as bar, impo\t \n " , "import foo as bar, importlib" ),
947
- ("import pri\t \n " , "import pri" ), # do not complete with "print("
948
949
("from impo\t \n " , "from importlib" ),
949
- ("from pri\t \n " , "from pri" ),
950
950
("from importlib.res\t \n " , "from importlib.resources" ),
951
951
("from importlib.\t \t res\t \n " , "from importlib.resources" ),
952
952
("from importlib.resources.ab\t \n " , "from importlib.resources.abc" ),
953
953
("from importlib import mac\t \n " , "from importlib import machinery" ),
954
954
("from importlib import res\t \n " , "from importlib import resources" ),
955
955
("from importlib.res\t import a\t \n " , "from importlib.resources import abc" ),
956
- ("from typing import Na\t \n " , "from typing import Na" ), # do not complete with "NameError("
957
956
)
958
957
for code , expected in cases :
959
958
with self .subTest (code = code ):
@@ -991,6 +990,20 @@ def test_invalid_identifiers(self):
991
990
output = reader .readline ()
992
991
self .assertEqual (output , expected )
993
992
993
+ def test_no_fallback_on_regular_completion (self ):
994
+ self ._only_stdlib_imports ()
995
+ cases = (
996
+ ("import pri\t \n " , "import pri" ),
997
+ ("from pri\t \n " , "from pri" ),
998
+ ("from typing import Na\t \n " , "from typing import Na" ),
999
+ )
1000
+ for code , expected in cases :
1001
+ with self .subTest (code = code ):
1002
+ events = code_to_events (code )
1003
+ reader = self .prepare_reader (events , namespace = {})
1004
+ output = reader .readline ()
1005
+ self .assertEqual (output , expected )
1006
+
994
1007
def test_get_path_and_prefix (self ):
995
1008
cases = (
996
1009
('' , ('' , '' )),
0 commit comments