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
da037616
Commit
da037616
authored
Jun 25, 2016
by
Brett Cannon
Browse files
Options
Browse Files
Download
Plain Diff
Merge from 3.5
parents
b466f8fa
e92dc9c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
4 deletions
+14
-4
Lib/importlib/util.py
Lib/importlib/util.py
+1
-1
Lib/test/test_importlib/test_lazy.py
Lib/test/test_importlib/test_lazy.py
+13
-3
No files found.
Lib/importlib/util.py
View file @
da037616
...
...
@@ -241,7 +241,7 @@ class _LazyModule(types.ModuleType):
if
id
(
self
)
!=
id
(
sys
.
modules
[
original_name
]):
msg
=
(
'module object for {!r} substituted in sys.modules '
'during a lazy load'
)
raise
ValueError
(
msg
.
format
(
original_name
))
raise
ValueError
(
msg
.
format
(
original_name
))
# Update after loading since that's what would happen in an eager
# loading situation.
self
.
__dict__
.
update
(
attrs_updated
)
...
...
Lib/test/test_importlib/test_lazy.py
View file @
da037616
import
importlib
from
importlib
import
abc
from
importlib
import
util
import
sys
import
types
import
unittest
from
.
import
util
as
test_util
...
...
@@ -122,12 +124,20 @@ class LazyLoaderTests(unittest.TestCase):
self
.
assertFalse
(
hasattr
(
module
,
'__name__'
))
def
test_module_substitution_error
(
self
):
source_code
=
'import sys; sys.modules[__name__] = 42'
module
=
self
.
new_module
(
source_code
)
with
test_util
.
uncache
(
TestingImporter
.
module_name
):
with
self
.
assertRaises
(
ValueError
):
fresh_module
=
types
.
ModuleType
(
TestingImporter
.
module_name
)
sys
.
modules
[
TestingImporter
.
module_name
]
=
fresh_module
module
=
self
.
new_module
()
with
self
.
assertRaisesRegex
(
ValueError
,
"substituted"
):
module
.
__name__
def
test_module_already_in_sys
(
self
):
with
test_util
.
uncache
(
TestingImporter
.
module_name
):
module
=
self
.
new_module
()
sys
.
modules
[
TestingImporter
.
module_name
]
=
module
# Force the load; just care that no exception is raised.
module
.
__name__
if
__name__
==
'__main__'
:
unittest
.
main
()
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