Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5e8b04e

Browse files
committed
Issue #21052: Don't raise ImportWarning for sys.meta_path or
sys.path_hooks when set to None during interpreter shutdown. Thanks to Martin Panter for the initial bug report.
1 parent 1aa3cb6 commit 5e8b04e

3 files changed

Lines changed: 31 additions & 26 deletions

File tree

Lib/importlib/_bootstrap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@ def _path_hooks(cls, path):
18061806
If 'hooks' is false then use sys.path_hooks.
18071807
18081808
"""
1809-
if not sys.path_hooks:
1809+
if sys.path_hooks is not None and not sys.path_hooks:
18101810
_warnings.warn('sys.path_hooks is empty', ImportWarning)
18111811
for hook in sys.path_hooks:
18121812
try:
@@ -2095,7 +2095,7 @@ def _find_spec_legacy(finder, name, path):
20952095

20962096
def _find_spec(name, path, target=None):
20972097
"""Find a module's loader."""
2098-
if not sys.meta_path:
2098+
if sys.meta_path is not None and not sys.meta_path:
20992099
_warnings.warn('sys.meta_path is empty', ImportWarning)
21002100
# We check sys.modules here for the reload case. While a passed-in
21012101
# target will usually indicate a reload there is no guarantee, whereas

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: TBA
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #21052: Do not raise ImportWarning when sys.path_hooks or sys.meta_path
14+
are set to None.
15+
1316
- Issue #16518: Use 'bytes-like object required' in error messages that
1417
previously used the far more cryptic "'x' does not support the buffer
1518
protocol.

Python/importlib.h

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3210,28 +3210,29 @@ const unsigned char _Py_M__importlib[] = {
32103210
80,97,116,104,70,105,110,100,101,114,46,105,110,118,97,108,
32113211
105,100,97,116,101,95,99,97,99,104,101,115,99,2,0,0,
32123212
0,0,0,0,0,3,0,0,0,12,0,0,0,67,0,0,
3213-
0,115,91,0,0,0,116,0,0,106,1,0,115,25,0,116,
3214-
2,0,106,3,0,100,1,0,116,4,0,131,2,0,1,120,
3213+
0,115,107,0,0,0,116,0,0,106,1,0,100,1,0,107,
3214+
9,0,114,41,0,116,0,0,106,1,0,12,114,41,0,116,
3215+
2,0,106,3,0,100,2,0,116,4,0,131,2,0,1,120,
32153216
59,0,116,0,0,106,1,0,68,93,44,0,125,2,0,121,
3216-
14,0,124,2,0,124,1,0,131,1,0,83,87,113,35,0,
3217-
4,116,5,0,107,10,0,114,78,0,1,1,1,119,35,0,
3218-
89,113,35,0,88,113,35,0,87,100,2,0,83,100,2,0,
3217+
14,0,124,2,0,124,1,0,131,1,0,83,87,113,51,0,
3218+
4,116,5,0,107,10,0,114,94,0,1,1,1,119,51,0,
3219+
89,113,51,0,88,113,51,0,87,100,1,0,83,100,1,0,
32193220
83,41,3,122,113,83,101,97,114,99,104,32,115,101,113,117,
32203221
101,110,99,101,32,111,102,32,104,111,111,107,115,32,102,111,
32213222
114,32,97,32,102,105,110,100,101,114,32,102,111,114,32,39,
32223223
112,97,116,104,39,46,10,10,32,32,32,32,32,32,32,32,
32233224
73,102,32,39,104,111,111,107,115,39,32,105,115,32,102,97,
32243225
108,115,101,32,116,104,101,110,32,117,115,101,32,115,121,115,
32253226
46,112,97,116,104,95,104,111,111,107,115,46,10,10,32,32,
3226-
32,32,32,32,32,32,122,23,115,121,115,46,112,97,116,104,
3227-
95,104,111,111,107,115,32,105,115,32,101,109,112,116,121,78,
3227+
32,32,32,32,32,32,78,122,23,115,121,115,46,112,97,116,
3228+
104,95,104,111,111,107,115,32,105,115,32,101,109,112,116,121,
32283229
41,6,114,7,0,0,0,218,10,112,97,116,104,95,104,111,
32293230
111,107,115,114,166,0,0,0,114,167,0,0,0,114,168,0,
32303231
0,0,114,153,0,0,0,41,3,114,8,1,0,0,114,35,
32313232
0,0,0,90,4,104,111,111,107,114,4,0,0,0,114,4,
32323233
0,0,0,114,5,0,0,0,218,11,95,112,97,116,104,95,
32333234
104,111,111,107,115,10,7,0,0,115,16,0,0,0,0,7,
3234-
9,1,16,1,16,1,3,1,14,1,13,1,12,2,122,22,
3235+
25,1,16,1,16,1,3,1,14,1,13,1,12,2,122,22,
32353236
80,97,116,104,70,105,110,100,101,114,46,95,112,97,116,104,
32363237
95,104,111,111,107,115,99,2,0,0,0,0,0,0,0,3,
32373238
0,0,0,11,0,0,0,67,0,0,0,115,94,0,0,0,
@@ -3732,28 +3733,29 @@ const unsigned char _Py_M__importlib[] = {
37323733
17,95,102,105,110,100,95,115,112,101,99,95,108,101,103,97,
37333734
99,121,39,8,0,0,115,8,0,0,0,0,3,18,1,12,
37343735
1,4,1,114,103,1,0,0,99,3,0,0,0,0,0,0,
3735-
0,9,0,0,0,26,0,0,0,67,0,0,0,115,25,1,
3736-
0,0,116,0,0,106,1,0,115,25,0,116,2,0,106,3,
3737-
0,100,1,0,116,4,0,131,2,0,1,124,0,0,116,0,
3736+
0,9,0,0,0,26,0,0,0,67,0,0,0,115,41,1,
3737+
0,0,116,0,0,106,1,0,100,1,0,107,9,0,114,41,
3738+
0,116,0,0,106,1,0,12,114,41,0,116,2,0,106,3,
3739+
0,100,2,0,116,4,0,131,2,0,1,124,0,0,116,0,
37383740
0,106,5,0,107,6,0,125,3,0,120,234,0,116,0,0,
37393741
106,1,0,68,93,219,0,125,4,0,116,6,0,131,0,0,
37403742
143,90,0,1,121,13,0,124,4,0,106,7,0,125,5,0,
3741-
87,110,51,0,4,116,8,0,107,10,0,114,132,0,1,1,
3743+
87,110,51,0,4,116,8,0,107,10,0,114,148,0,1,1,
37423744
1,116,9,0,124,4,0,124,0,0,124,1,0,131,3,0,
3743-
125,6,0,124,6,0,100,2,0,107,8,0,114,128,0,119,
3744-
50,0,89,110,19,0,88,124,5,0,124,0,0,124,1,0,
3745-
124,2,0,131,3,0,125,6,0,87,100,2,0,81,88,124,
3746-
6,0,100,2,0,107,9,0,114,50,0,124,3,0,12,114,
3747-
9,1,124,0,0,116,0,0,106,5,0,107,6,0,114,9,
3745+
125,6,0,124,6,0,100,1,0,107,8,0,114,144,0,119,
3746+
66,0,89,110,19,0,88,124,5,0,124,0,0,124,1,0,
3747+
124,2,0,131,3,0,125,6,0,87,100,1,0,81,88,124,
3748+
6,0,100,1,0,107,9,0,114,66,0,124,3,0,12,114,
3749+
25,1,124,0,0,116,0,0,106,5,0,107,6,0,114,25,
37483750
1,116,0,0,106,5,0,124,0,0,25,125,7,0,121,13,
37493751
0,124,7,0,106,10,0,125,8,0,87,110,22,0,4,116,
3750-
8,0,107,10,0,114,241,0,1,1,1,124,6,0,83,89,
3751-
113,13,1,88,124,8,0,100,2,0,107,8,0,114,2,1,
3752-
124,6,0,83,124,8,0,83,113,50,0,124,6,0,83,113,
3753-
50,0,87,100,2,0,83,100,2,0,83,41,3,122,23,70,
3752+
8,0,107,10,0,114,1,1,1,1,1,124,6,0,83,89,
3753+
113,29,1,88,124,8,0,100,1,0,107,8,0,114,18,1,
3754+
124,6,0,83,124,8,0,83,113,66,0,124,6,0,83,113,
3755+
66,0,87,100,1,0,83,100,1,0,83,41,3,122,23,70,
37543756
105,110,100,32,97,32,109,111,100,117,108,101,39,115,32,108,
3755-
111,97,100,101,114,46,122,22,115,121,115,46,109,101,116,97,
3756-
95,112,97,116,104,32,105,115,32,101,109,112,116,121,78,41,
3757+
111,97,100,101,114,46,78,122,22,115,121,115,46,109,101,116,
3758+
97,95,112,97,116,104,32,105,115,32,101,109,112,116,121,41,
37573759
11,114,7,0,0,0,218,9,109,101,116,97,95,112,97,116,
37583760
104,114,166,0,0,0,114,167,0,0,0,114,168,0,0,0,
37593761
114,73,0,0,0,114,99,1,0,0,114,10,1,0,0,114,
@@ -3763,7 +3765,7 @@ const unsigned char _Py_M__importlib[] = {
37633765
10,1,0,0,114,176,0,0,0,114,177,0,0,0,114,206,
37643766
0,0,0,114,4,0,0,0,114,4,0,0,0,114,5,0,
37653767
0,0,218,10,95,102,105,110,100,95,115,112,101,99,48,8,
3766-
0,0,115,48,0,0,0,0,2,9,1,16,4,15,1,16,
3768+
0,0,115,48,0,0,0,0,2,25,1,16,4,15,1,16,
37673769
1,10,1,3,1,13,1,13,1,18,1,12,1,8,2,24,
37683770
1,12,2,22,1,13,1,3,1,13,1,13,4,9,2,12,
37693771
1,4,2,7,2,8,2,114,105,1,0,0,99,3,0,0,

0 commit comments

Comments
 (0)