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
7c97a056
Commit
7c97a056
authored
Aug 14, 2015
by
Brett Cannon
Browse files
Options
Browse Files
Download
Plain Diff
Merge from 3.5.0 for issue #24492
parents
f7a92673
3008bc0f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
7 deletions
+29
-7
Lib/test/test_import/__init__.py
Lib/test/test_import/__init__.py
+13
-0
Misc/NEWS
Misc/NEWS
+4
-0
Python/ceval.c
Python/ceval.c
+12
-7
No files found.
Lib/test/test_import/__init__.py
View file @
7c97a056
...
...
@@ -324,6 +324,19 @@ class ImportTests(unittest.TestCase):
with
self
.
assertRaisesRegex
(
ImportError
,
"^cannot import name 'bogus'"
):
from
re
import
bogus
def
test_from_import_AttributeError
(
self
):
# Issue #24492: trying to import an attribute that raises an
# AttributeError should lead to an ImportError.
class
AlwaysAttributeError
:
def
__getattr__
(
self
,
_
):
raise
AttributeError
module_name
=
'test_from_import_AttributeError'
self
.
addCleanup
(
unload
,
module_name
)
sys
.
modules
[
module_name
]
=
AlwaysAttributeError
()
with
self
.
assertRaises
(
ImportError
):
from
test_from_import_AttributeError
import
does_not_exist
@
skip_if_dont_write_bytecode
class
FilePermissionTests
(
unittest
.
TestCase
):
...
...
Misc/NEWS
View file @
7c97a056
...
...
@@ -37,6 +37,10 @@ Release date: 2015-08-09
Core
and
Builtins
-----------------
-
Issue
#
24492
:
A
"package"
lacking
a
__name__
attribute
when
trying
to
perform
a
``
from
..
import
...``
statement
will
trigger
an
ImportError
instead
of
an
AttributeError
.
-
Issue
#
24667
:
Resize
odict
in
all
cases
that
the
underlying
dict
resizes
.
Library
...
...
Python/ceval.c
View file @
7c97a056
...
...
@@ -5085,19 +5085,24 @@ import_from(PyObject *v, PyObject *name)
sys.modules. */
PyErr_Clear
();
pkgname
=
_PyObject_GetAttrId
(
v
,
&
PyId___name__
);
if
(
pkgname
==
NULL
)
return
NULL
;
if
(
pkgname
==
NULL
)
{
goto
error
;
}
fullmodname
=
PyUnicode_FromFormat
(
"%U.%U"
,
pkgname
,
name
);
Py_DECREF
(
pkgname
);
if
(
fullmodname
==
NULL
)
if
(
fullmodname
==
NULL
)
{
return
NULL
;
}
x
=
PyDict_GetItem
(
PyImport_GetModuleDict
(),
fullmodname
);
if
(
x
==
NULL
)
PyErr_Format
(
PyExc_ImportError
,
"cannot import name %R"
,
name
);
else
Py_INCREF
(
x
);
Py_DECREF
(
fullmodname
);
if
(
x
==
NULL
)
{
goto
error
;
}
Py_INCREF
(
x
);
return
x
;
error:
PyErr_Format
(
PyExc_ImportError
,
"cannot import name %R"
,
name
);
return
NULL
;
}
static
int
...
...
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