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 @@ -37,7 +37,9 @@ What's New in astroid 3.3.10?
3737=============================
3838Release date: TBA
3939
40+ * Avoid importing submodules sharing names with standard library modules.
4041
42+ Closes #2684
4143
4244
4345What's New in astroid 3.3.9?
Original file line number Diff line number Diff line change @@ -174,7 +174,7 @@ def find_module(
174174 # module. Note that `find_spec` actually imports parent modules, so we want to make
175175 # sure we only run this code for stuff that can be expected to be frozen. For now
176176 # this is only stdlib.
177- if modname in sys .stdlib_module_names or (
177+ if ( modname in sys .stdlib_module_names and not processed ) or (
178178 processed and processed [0 ] in sys .stdlib_module_names
179179 ):
180180 try :
Original file line number Diff line number Diff line change @@ -628,3 +628,18 @@ def test_find_setuptools_pep660_editable_install():
628628 with unittest .mock .patch .object (sys , "meta_path" , new = [_EditableFinder ]):
629629 assert spec .find_spec (["example" ])
630630 assert spec .find_spec (["example" , "subpackage" ])
631+
632+
633+ def test_no_import_done_for_submodule_sharing_std_lib_name () -> None :
634+ sys .path .insert (0 , resources .find ("data" ))
635+ try :
636+ with pytest .raises (ImportError ):
637+ spec ._find_spec_with_path (
638+ [resources .find ("data" )],
639+ "trace" ,
640+ ("divide_by_zero" , "trace" ),
641+ ("divide_by_zero" ,),
642+ resources .find ("data/divide_by_zero" ),
643+ )
644+ finally :
645+ 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