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?
37
37
=============================
38
38
Release date: TBA
39
39
40
+ * Avoid importing submodules sharing names with standard library modules.
40
41
42
+ Closes #2684
41
43
42
44
43
45
What's New in astroid 3.3.9?
Original file line number Diff line number Diff line change @@ -174,7 +174,7 @@ def find_module(
174
174
# module. Note that `find_spec` actually imports parent modules, so we want to make
175
175
# sure we only run this code for stuff that can be expected to be frozen. For now
176
176
# 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 (
178
178
processed and processed [0 ] in sys .stdlib_module_names
179
179
):
180
180
try :
Original file line number Diff line number Diff line change @@ -628,3 +628,18 @@ def test_find_setuptools_pep660_editable_install():
628
628
with unittest .mock .patch .object (sys , "meta_path" , new = [_EditableFinder ]):
629
629
assert spec .find_spec (["example" ])
630
630
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