Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
6bfb6480
Commit
6bfb6480
authored
Oct 13, 2011
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
from a import b: raise ImportError instead of AttributeError, fix #734
parent
b6f77033
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
3 deletions
+36
-3
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+26
-3
tests/run/import_error_T734.py
tests/run/import_error_T734.py
+10
-0
No files found.
Cython/Compiler/Nodes.py
View file @
6bfb6480
...
...
@@ -5984,6 +5984,8 @@ class FromImportStatNode(StatNode):
else
:
coerced_item
=
self
.
item
.
coerce_to
(
target
.
type
,
env
)
self
.
interned_items
.
append
((
name
,
target
,
coerced_item
))
if
self
.
interned_items
:
env
.
use_utility_code
(
raise_import_error_utility_code
)
def
generate_execution_code
(
self
,
code
):
self
.
module
.
generate_evaluation_code
(
code
)
...
...
@@ -5998,11 +6000,16 @@ class FromImportStatNode(StatNode):
for
name
,
target
,
coerced_item
in
self
.
interned_items
:
cname
=
code
.
intern_identifier
(
name
)
code
.
putln
(
'%s = PyObject_GetAttr(%s, %s);
%s
'
%
(
'%s = PyObject_GetAttr(%s, %s);'
%
(
item_temp
,
self
.
module
.
py_result
(),
cname
,
code
.
error_goto_if_null
(
item_temp
,
self
.
pos
)))
cname
))
code
.
putln
(
'if (%s == NULL) {'
%
item_temp
)
code
.
putln
(
'if (PyErr_ExceptionMatches(PyExc_AttributeError)) '
'__Pyx_RaiseImportError(%s);'
%
cname
)
code
.
putln
(
code
.
error_goto_if_null
(
item_temp
,
self
.
pos
))
code
.
putln
(
'}'
)
code
.
put_gotref
(
item_temp
)
if
coerced_item
is
None
:
target
.
generate_assignment_code
(
self
.
item
,
code
)
...
...
@@ -8332,3 +8339,19 @@ init="""
memset(&%(PYX_NAN)s, 0xFF, sizeof(%(PYX_NAN)s));
"""
%
vars
(
Naming
))
#------------------------------------------------------------------------------------
raise_import_error_utility_code
=
UtilityCode
(
proto
=
'''
static CYTHON_INLINE void __Pyx_RaiseImportError(PyObject *name);
'''
,
impl
=
'''
static CYTHON_INLINE void __Pyx_RaiseImportError(PyObject *name) {
#if PY_MAJOR_VERSION < 3
PyErr_Format(PyExc_ImportError, "cannot import name %.230s",
PyString_AsString(name));
#else
PyErr_Format(PyExc_ImportError, "cannot import name %S", name);
#endif
}
'''
)
tests/run/import_error_T734.py
0 → 100644
View file @
6bfb6480
# mode: run
# ticket: 734
def
test_import_error
():
"""
>>> test_import_error()
Traceback (most recent call last):
ImportError: cannot import name xxx
"""
from
sys
import
xxx
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