Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue31642

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:None value in sys.modules no longer blocks import
Type:behaviorStage:resolved
Components:Interpreter CoreVersions:Python 3.7, Python 3.6
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To:Nosy List: barry, brett.cannon, christian.heimes, eric.snow, ncoghlan, serhiy.storchaka
Priority:normalKeywords:3.6regression, patch

Created on2017-09-29 20:21 bychristian.heimes, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Pull Requests
URLStatusLinkedEdit
PR 3834mergedserhiy.storchaka,2017-09-30 06:47
PR 3923mergedserhiy.storchaka,2017-10-08 08:15
Messages (5)
msg303356 -(view)Author: Christian Heimes (christian.heimes)*(Python committer)Date: 2017-09-29 20:21
Since Python 3.6, the blocking of imports is broken for 'from package import module' imports.$ mkdir a$ touch a/__init__.py a/b.py>>> import sys>>> sys.modules['a.b'] = None>>> from a import b>>> b is NoneTrue>>> import a.bTraceback (most recent call last):  File "<stdin>", line 1, in <module>ModuleNotFoundError: import of 'a.b' halted; None in sys.modulesTests with Python 2.7 to master:$ python2.7 -c "from a import b; print(b)"<module 'a.b' from 'a/b.py'>$ python2.7 -c "import sys; sys.modules['a.b'] = None; from a import b"Traceback (most recent call last):  File "<string>", line 1, in <module>ImportError: cannot import name b$ python2.7 -c "import sys; sys.modules['a.b'] = None; from a import b"Traceback (most recent call last):  File "<string>", line 1, in <module>ImportError: cannot import name b$ python3.4 -c "import sys; sys.modules['a.b'] = None; from a import b"Traceback (most recent call last):  File "<string>", line 1, in <module>ImportError: import of 'a.b' halted; None in sys.modules$ python3.5 -c "import sys; sys.modules['a.b'] = None; from a import b"Traceback (most recent call last):  File "<string>", line 1, in <module>ImportError: import of 'a.b' halted; None in sys.modules$ python3.6 -c "import sys; sys.modules['a.b'] = None; from a import b"$ ./python -c "import sys; sys.modules['a.b'] = None; from a import b"
msg303374 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2017-09-29 23:42
This is a side effect ofissue15767. The exception is raised in _find_and_load, but it is always silenced in _handle_fromlist.
msg303396 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2017-09-30 06:56
PR 3834 provide possible solution of this issue.Initially import errors were silenced for solvingissue15715. An import error raised when import was blocked by setting None in sys.modules was not silenced because it has different error message. I don't know whether this was intentional. Inissue15767 (5fdb8c897023) the error message test was replaced by the type test, and that exception become silenced (I suppose it was not intentional).
msg303900 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2017-10-08 07:44
New changesetf07e2b64df6304a36fb5e29397d3c77a7ba17704 by Serhiy Storchaka in branch 'master':bpo-31642: Restore blocking "from" import by setting None in sys.modules. (#3834)https://github.com/python/cpython/commit/f07e2b64df6304a36fb5e29397d3c77a7ba17704
msg303904 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2017-10-08 09:52
New changeset6f059ab80a351a7dd85cc57c5ca240f817a79c5d by Serhiy Storchaka in branch '3.6':[3.6]bpo-31642: Restore blocking "from" import by setting None in sys.modules. (GH-3834). (#3923)https://github.com/python/cpython/commit/6f059ab80a351a7dd85cc57c5ca240f817a79c5d
History
DateUserActionArgs
2022-04-11 14:58:52adminsetgithub: 75823
2017-10-08 09:55:13serhiy.storchakasetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: - Python 3.8
2017-10-08 09:52:00serhiy.storchakasetmessages: +msg303904
2017-10-08 08:15:31serhiy.storchakasetpull_requests: +pull_request3896
2017-10-08 07:44:12serhiy.storchakasetmessages: +msg303900
2017-09-30 06:56:34serhiy.storchakasetmessages: +msg303396
2017-09-30 06:47:08serhiy.storchakasetkeywords: +patch
stage: needs patch -> patch review
pull_requests: +pull_request3815
2017-09-29 23:42:25serhiy.storchakasetmessages: +msg303374
2017-09-29 20:32:45barrysetnosy: +barry
2017-09-29 20:23:21serhiy.storchakasetnosy: +serhiy.storchaka
2017-09-29 20:22:23christian.heimessettype: behavior
stage: needs patch
2017-09-29 20:22:13christian.heimessetnosy: +brett.cannon,ncoghlan,eric.snow
2017-09-29 20:21:12christian.heimescreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp