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?
13
13
=============================
14
14
Release date: TBA
15
15
16
+ * Avoid importing submodules sharing names with standard library modules.
16
17
18
+ Closes #2684
17
19
18
20
What's New in astroid 3.3.9?
19
21
============================
Original file line number Diff line number Diff line change @@ -171,7 +171,7 @@ def find_module(
171
171
# module. Note that `find_spec` actually imports parent modules, so we want to make
172
172
# sure we only run this code for stuff that can be expected to be frozen. For now
173
173
# 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 (
175
175
processed and processed [0 ] in sys .stdlib_module_names
176
176
):
177
177
try :
Original file line number Diff line number Diff line change @@ -597,3 +597,18 @@ def test_find_setuptools_pep660_editable_install():
597
597
with unittest .mock .patch .object (sys , "meta_path" , new = [_EditableFinder ]):
598
598
assert spec .find_spec (["example" ])
599
599
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