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
b206a80d
Commit
b206a80d
authored
Apr 16, 2012
by
Brian Curtin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #10854. Make use of the new path and name attributes on ImportError
for extension modules on Windows.
parent
15439817
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
2 deletions
+25
-2
Lib/test/test_import.py
Lib/test/test_import.py
+18
-0
Misc/NEWS
Misc/NEWS
+4
-0
Python/dynload_win.c
Python/dynload_win.c
+3
-2
No files found.
Lib/test/test_import.py
View file @
b206a80d
...
@@ -337,6 +337,24 @@ class ImportTests(unittest.TestCase):
...
@@ -337,6 +337,24 @@ class ImportTests(unittest.TestCase):
del
sys
.
path
[
0
]
del
sys
.
path
[
0
]
remove_files
(
TESTFN
)
remove_files
(
TESTFN
)
@
unittest
.
skipUnless
(
sys
.
platform
==
"win32"
,
"Windows specific"
)
def
test_extension_import_fail
(
self
):
# Issue 1559549 added `name` and `path` attributes to ImportError
# in order to provide better detail. Issue 10854 implemented those
# attributes on import failures of extensions on Windows.
debug
=
True
if
sys
.
executable
[
-
6
:]
==
"_d.exe"
else
False
pkg_name
=
"extension"
pkg_file
=
pkg_name
+
"{}"
.
format
(
"_d.pyd"
if
debug
else
".pyd"
)
with
open
(
pkg_file
,
"w"
):
pass
try
:
with
self
.
assertRaises
(
ImportError
)
as
err
:
import
extension
self
.
assertEqual
(
err
.
exception
.
name
,
pkg_name
)
# The path we get back has the dot-slash, e.g., ".\\extension.pyd"
self
.
assertEqual
(
os
.
path
.
relpath
(
err
.
exception
.
path
),
pkg_file
)
finally
:
unlink
(
pkg_file
)
class
PycRewritingTests
(
unittest
.
TestCase
):
class
PycRewritingTests
(
unittest
.
TestCase
):
# Test that the `co_filename` attribute on code objects always points
# Test that the `co_filename` attribute on code objects always points
...
...
Misc/NEWS
View file @
b206a80d
...
@@ -10,6 +10,10 @@ What's New in Python 3.3.0 Alpha 3?
...
@@ -10,6 +10,10 @@ What's New in Python 3.3.0 Alpha 3?
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #10854: The ImportError raised when an extension module on Windows
fails to import now uses the new path and name attributes from
Issue #1559549.
- Issue #14582: Import directly returns the module as returned by a loader when
- Issue #14582: Import directly returns the module as returned by a loader when
possible instead of fetching it from sys.modules.
possible instead of fetching it from sys.modules.
...
...
Python/dynload_win.c
View file @
b206a80d
...
@@ -254,8 +254,9 @@ dl_funcptr _PyImport_GetDynLoadWindows(const char *shortname,
...
@@ -254,8 +254,9 @@ dl_funcptr _PyImport_GetDynLoadWindows(const char *shortname,
theLength
));
theLength
));
}
}
if
(
message
!=
NULL
)
{
if
(
message
!=
NULL
)
{
PyErr_SetObject
(
PyExc_ImportError
,
message
);
PyErr_SetFromImportErrorWithNameAndPath
(
message
,
Py_DECREF
(
message
);
PyUnicode_FromString
(
shortname
),
pathname
);
}
}
return
NULL
;
return
NULL
;
}
else
{
}
else
{
...
...
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