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
4d75fc1c
Commit
4d75fc1c
authored
Aug 30, 2009
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Have importlib raise ImportError if None is found in sys.modules. This matches
current import semantics.
parent
ccd686a4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
5 deletions
+22
-5
Lib/importlib/_bootstrap.py
Lib/importlib/_bootstrap.py
+6
-1
Lib/importlib/test/import_/test_caching.py
Lib/importlib/test/import_/test_caching.py
+14
-4
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/importlib/_bootstrap.py
View file @
4d75fc1c
...
...
@@ -864,7 +864,12 @@ def _gcd_import(name, package=None, level=0):
name
=
package
[:
dot
]
with
_ImportLockContext
():
try
:
return
sys
.
modules
[
name
]
module
=
sys
.
modules
[
name
]
if
module
is
None
:
message
=
(
"import of {} halted; "
"None in sys.modules"
.
format
(
name
))
raise
ImportError
(
message
)
return
module
except
KeyError
:
pass
parent
=
name
.
rpartition
(
'.'
)[
0
]
...
...
Lib/importlib/test/import_/test_caching.py
View file @
4d75fc1c
...
...
@@ -17,15 +17,25 @@ class UseCache(unittest.TestCase):
loader returns) [from cache on return]. This also applies to imports of
things contained within a package and thus get assigned as an attribute
[from cache to attribute] or pulled in thanks to a fromlist import
[from cache for fromlist].
[from cache for fromlist]. But if sys.modules contains None then
ImportError is raised [None in cache].
"""
def
test_using_cache
(
self
):
# [use cache]
module_to_use
=
"some module found!"
sys
.
modules
[
'some_module'
]
=
module_to_use
module
=
import_util
.
import_
(
'some_module'
)
self
.
assertEqual
(
id
(
module_to_use
),
id
(
module
))
with
util
.
uncache
(
module_to_use
):
sys
.
modules
[
'some_module'
]
=
module_to_use
module
=
import_util
.
import_
(
'some_module'
)
self
.
assertEqual
(
id
(
module_to_use
),
id
(
module
))
def
test_None_in_cache
(
self
):
#[None in cache]
name
=
'using_None'
with
util
.
uncache
(
name
):
sys
.
modules
[
name
]
=
None
with
self
.
assertRaises
(
ImportError
):
import_util
.
import_
(
name
)
def
create_mock
(
self
,
*
names
,
return_
=
None
):
mock
=
util
.
mock_modules
(
*
names
)
...
...
Misc/NEWS
View file @
4d75fc1c
...
...
@@ -68,6 +68,8 @@ C-API
Library
-------
- Have importlib raise ImportError if None is found in sys.modules.
- Issue #6054: Do not normalize stored pathnames in tarfile.
- Issue #6794: Fix Decimal.compare_total and Decimal.compare_total_mag: NaN
...
...
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