Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f07e2b64
Commit
f07e2b64
authored
Oct 08, 2017
by
Serhiy Storchaka
Committed by
GitHub
Oct 08, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-31642: Restore blocking "from" import by setting None in sys.modules. (#3834)
parent
73ffd3f2
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
262 additions
and
243 deletions
+262
-243
Lib/importlib/_bootstrap.py
Lib/importlib/_bootstrap.py
+2
-1
Lib/test/test_importlib/import_/test_api.py
Lib/test/test_importlib/import_/test_api.py
+14
-0
Misc/NEWS.d/next/Core and Builtins/2017-10-08-10-00-55.bpo-31642.1IKqgs.rst
...ore and Builtins/2017-10-08-10-00-55.bpo-31642.1IKqgs.rst
+2
-0
Python/importlib.h
Python/importlib.h
+244
-242
No files found.
Lib/importlib/_bootstrap.py
View file @
f07e2b64
...
...
@@ -1019,7 +1019,8 @@ def _handle_fromlist(module, fromlist, import_):
# Backwards-compatibility dictates we ignore failed
# imports triggered by fromlist for modules that don't
# exist.
if
exc
.
name
==
from_name
:
if
(
exc
.
name
==
from_name
and
sys
.
modules
.
get
(
from_name
,
_NEEDS_LOADING
)
is
not
None
):
continue
raise
return
module
...
...
Lib/test/test_importlib/import_/test_api.py
View file @
f07e2b64
...
...
@@ -82,6 +82,20 @@ class APITest:
self
.
__import__
(
PKG_NAME
,
fromlist
=
[
SUBMOD_NAME
.
rpartition
(
'.'
)[
-
1
]])
def
test_blocked_fromlist
(
self
):
# If fromlist entry is None, let a ModuleNotFoundError propagate.
# issue31642
mod
=
types
.
ModuleType
(
PKG_NAME
)
mod
.
__path__
=
[]
with
util
.
import_state
(
meta_path
=
[
self
.
bad_finder_loader
]):
with
util
.
uncache
(
PKG_NAME
,
SUBMOD_NAME
):
sys
.
modules
[
PKG_NAME
]
=
mod
sys
.
modules
[
SUBMOD_NAME
]
=
None
with
self
.
assertRaises
(
ModuleNotFoundError
)
as
cm
:
self
.
__import__
(
PKG_NAME
,
fromlist
=
[
SUBMOD_NAME
.
rpartition
(
'.'
)[
-
1
]])
self
.
assertEqual
(
cm
.
exception
.
name
,
SUBMOD_NAME
)
class
OldAPITests
(
APITest
):
bad_finder_loader
=
BadLoaderFinder
...
...
Misc/NEWS.d/next/Core and Builtins/2017-10-08-10-00-55.bpo-31642.1IKqgs.rst
0 → 100644
View file @
f07e2b64
Restored blocking "from package import module" by setting
sys.modules["package.module"] to None.
Python/importlib.h
View file @
f07e2b64
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment