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
7d8a6861
Commit
7d8a6861
authored
Aug 30, 2009
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow importlib.__import__ to accept any iterable for fromlist. Discovered when
running importlib against test___all__.
parent
e8525e0b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
2 deletions
+12
-2
Lib/importlib/_bootstrap.py
Lib/importlib/_bootstrap.py
+1
-0
Lib/importlib/test/import_/test_fromlist.py
Lib/importlib/test/import_/test_fromlist.py
+9
-2
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/importlib/_bootstrap.py
View file @
7d8a6861
...
...
@@ -943,6 +943,7 @@ def __import__(name, globals={}, locals={}, fromlist=[], level=0):
# If a package was imported, try to import stuff from fromlist.
if
hasattr
(
module
,
'__path__'
):
if
'*'
in
fromlist
and
hasattr
(
module
,
'__all__'
):
fromlist
=
list
(
fromlist
)
fromlist
.
remove
(
'*'
)
fromlist
.
extend
(
module
.
__all__
)
for
x
in
(
y
for
y
in
fromlist
if
not
hasattr
(
module
,
y
)):
...
...
Lib/importlib/test/import_/test_fromlist.py
View file @
7d8a6861
...
...
@@ -84,16 +84,23 @@ class HandlingFromlist(unittest.TestCase):
module
=
import_util
.
import_
(
'pkg.mod'
,
fromlist
=
[
''
])
self
.
assertEquals
(
module
.
__name__
,
'pkg.mod'
)
def
test_using_star
(
self
):
def
basic_star_test
(
self
,
fromlist
=
[
'*'
]
):
# [using *]
with
util
.
mock_modules
(
'pkg.__init__'
,
'pkg.module'
)
as
mock
:
with
util
.
import_state
(
meta_path
=
[
mock
]):
mock
[
'pkg'
].
__all__
=
[
'module'
]
module
=
import_util
.
import_
(
'pkg'
,
fromlist
=
[
'*'
]
)
module
=
import_util
.
import_
(
'pkg'
,
fromlist
=
fromlist
)
self
.
assertEquals
(
module
.
__name__
,
'pkg'
)
self
.
assertTrue
(
hasattr
(
module
,
'module'
))
self
.
assertEqual
(
module
.
module
.
__name__
,
'pkg.module'
)
def
test_using_star
(
self
):
# [using *]
self
.
basic_star_test
()
def
test_fromlist_as_tuple
(
self
):
self
.
basic_star_test
((
'*'
,))
def
test_star_with_others
(
self
):
# [using * with others]
context
=
util
.
mock_modules
(
'pkg.__init__'
,
'pkg.module1'
,
'pkg.module2'
)
...
...
Misc/NEWS
View file @
7d8a6861
...
...
@@ -68,6 +68,8 @@ C-API
Library
-------
- Allow the fromlist passed into importlib.__import__ to be any iterable.
- Have importlib raise ImportError if None is found in sys.modules.
- Issue #6054: Do not normalize stored pathnames in tarfile.
...
...
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