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
0911c0d2
Commit
0911c0d2
authored
Feb 20, 2016
by
Brett Cannon
Browse files
Options
Browse Files
Download
Plain Diff
Merge for issue #26367
parents
d9dc5302
4f38cb41
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
410 additions
and
394 deletions
+410
-394
Lib/importlib/_bootstrap.py
Lib/importlib/_bootstrap.py
+4
-1
Lib/test/test_importlib/import_/test_relative_imports.py
Lib/test/test_importlib/import_/test_relative_imports.py
+5
-0
Misc/NEWS
Misc/NEWS
+3
-0
Python/importlib.h
Python/importlib.h
+398
-393
No files found.
Lib/importlib/_bootstrap.py
View file @
0911c0d2
...
...
@@ -922,9 +922,12 @@ def _sanity_check(name, package, level):
raise
TypeError
(
'module name must be str, not {}'
.
format
(
type
(
name
)))
if
level
<
0
:
raise
ValueError
(
'level must be >= 0'
)
if
package
:
if
level
>
0
:
if
not
isinstance
(
package
,
str
):
raise
TypeError
(
'__package__ not set to a string'
)
elif
not
package
:
raise
ImportError
(
'attempted relative import with no known parent '
'package'
)
elif
package
not
in
sys
.
modules
:
msg
=
(
'Parent module {!r} not loaded, cannot perform relative '
'import'
)
...
...
Lib/test/test_importlib/import_/test_relative_imports.py
View file @
0911c0d2
...
...
@@ -218,6 +218,11 @@ class RelativeImports:
self
.
__import__
(
'a'
,
{
'__package__'
:
''
,
'__spec__'
:
None
},
level
=
1
)
def
test_relative_import_no_package_exists_absolute
(
self
):
with
self
.
assertRaises
(
ImportError
):
self
.
__import__
(
'sys'
,
{
'__package__'
:
''
,
'__spec__'
:
None
},
level
=
1
)
(
Frozen_RelativeImports
,
Source_RelativeImports
...
...
Misc/NEWS
View file @
0911c0d2
...
...
@@ -185,6 +185,9 @@ Core and Builtins
Library
-------
-
Issue
#
26367
:
importlib
.
__init__
()
raises
ImportError
like
builtins
.
__import__
()
when
``
level
``
is
specified
but
without
an
accompanying
package
specified
.
-
Issue
#
26309
:
In
the
"socketserver"
module
,
shut
down
the
request
(
closing
the
connected
socket
)
when
verify_request
()
returns
false
.
Patch
by
Aviv
...
...
Python/importlib.h
View file @
0911c0d2
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