File tree Expand file tree Collapse file tree 4 files changed +19
-1
lines changed
astroid/interpreter/_import Expand file tree Collapse file tree 4 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,9 @@ What's New in astroid 3.3.10?
1313=============================
1414Release date: TBA
1515
16+ * Avoid importing submodules sharing names with standard library modules.
1617
18+ Closes #2684
1719
1820What's New in astroid 3.3.9?
1921============================
Original file line number Diff line number Diff line change @@ -171,7 +171,7 @@ def find_module(
171171 # module. Note that `find_spec` actually imports parent modules, so we want to make
172172 # sure we only run this code for stuff that can be expected to be frozen. For now
173173 # this is only stdlib.
174- if modname in sys .stdlib_module_names or (
174+ if ( modname in sys .stdlib_module_names and not processed ) or (
175175 processed and processed [0 ] in sys .stdlib_module_names
176176 ):
177177 try :
Original file line number Diff line number Diff line change @@ -597,3 +597,18 @@ def test_find_setuptools_pep660_editable_install():
597597 with unittest .mock .patch .object (sys , "meta_path" , new = [_EditableFinder ]):
598598 assert spec .find_spec (["example" ])
599599 assert spec .find_spec (["example" , "subpackage" ])
600+
601+
602+ def test_no_import_done_for_submodule_sharing_std_lib_name () -> None :
603+ sys .path .insert (0 , resources .find ("data" ))
604+ try :
605+ with pytest .raises (ImportError ):
606+ spec ._find_spec_with_path (
607+ [resources .find ("data" )],
608+ "trace" ,
609+ ("divide_by_zero" , "trace" ),
610+ ("divide_by_zero" ,),
611+ resources .find ("data/divide_by_zero" ),
612+ )
613+ finally :
614+ sys .path .pop (0 )
Original file line number Diff line number Diff line change 1+ 1 / 0
You can’t perform that action at this time.
0 commit comments