@@ -1324,6 +1324,7 @@ def test_attribute_completion_module_on_demand(self):
13241324 (dir / "pack" / "foo.py" ).touch ()
13251325 (dir / "pack" / "bar.py" ).touch ()
13261326 (dir / "pack" / "baz.py" ).touch ()
1327+ sys .modules .pop ("graphlib" , None ) # test modules may have been imported by previous tests
13271328 with patch .object (sys , "path" , [_dir , * sys .path ]):
13281329 cases = (
13291330 # needs 2 tabs to import (show prompt, then import)
@@ -1344,6 +1345,8 @@ def test_attribute_completion_module_on_demand(self):
13441345 ("from pack import b\t \n " , "from pack import ba" , set ()),
13451346 ("from pack import b\t \t \n " , "from pack import ba" , set ()),
13461347 ("from pack import b\t \t \t \n " , "from pack import ba" , {"pack" }),
1348+ # stdlib modules are automatically imported
1349+ ("from graphlib import T\t \n " , "from graphlib import TopologicalSorter" , {"graphlib" }),
13471350 )
13481351 for code , expected , expected_imports in cases :
13491352 with self .subTest (code = code ), patch .dict (sys .modules ):
@@ -1554,6 +1557,8 @@ def test_suggestions_and_messages(self) -> None:
15541557 (dir / "pack" ).mkdir ()
15551558 (dir / "pack" / "__init__.py" ).write_text ("foo = 1; bar = 2;" )
15561559 (dir / "pack" / "bar.py" ).touch ()
1560+ sys .modules .pop ("graphlib" , None ) # test modules may have been imported by previous tests
1561+ sys .modules .pop ("compression.zstd" , None )
15571562 with patch .object (sys , "path" , [_dir , * sys .path ]):
15581563 cases = (
15591564 # no match != not an import
@@ -1575,6 +1580,9 @@ def test_suggestions_and_messages(self) -> None:
15751580 ("from pack import " , (["bar" , "foo" ], None ), set ()),
15761581 ("from pack.bar import " , ([], (_prompt , None )), {"pack.bar" }),
15771582 ("from pack.bar import " , ([], None ), set ()),
1583+ # stdlib = auto-imported
1584+ ("from graphlib import T" , (["TopologicalSorter" ], None ), {"graphlib" }),
1585+ ("from compression.zstd import c" , (["compress" ], None ), {"compression.zstd" }),
15781586 )
15791587 completer = ModuleCompleter ()
15801588 for i , (code , expected , expected_imports ) in enumerate (cases ):
@@ -1594,8 +1602,6 @@ def test_suggestions_and_messages(self) -> None:
15941602
15951603 new_imports = sys .modules .keys () - _imported
15961604 self .assertSetEqual (new_imports , expected_imports )
1597- for mod in new_imports :
1598- self .addCleanup (sys .modules .pop , mod )
15991605
16001606class TestHardcodedSubmodules (TestCase ):
16011607 @patch .dict (sys .modules )
0 commit comments